From 6ad51b036ea2f3a627647a6e0122b25c12fc0924 Mon Sep 17 00:00:00 2001 From: Roger Far Date: Fri, 5 Jan 2024 10:37:07 -0700 Subject: [PATCH] Store the torrent name instead of the hash to the blackhole directory. --- .../Helpers/DownloadHelper.cs | 7 +------ .../RdtClient.Service/Helpers/FileHelper.cs | 5 +++++ server/RdtClient.Service/Services/Torrents.cs | 20 +++++++++++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/server/RdtClient.Service/Helpers/DownloadHelper.cs b/server/RdtClient.Service/Helpers/DownloadHelper.cs index 7b53569..e6a5966 100644 --- a/server/RdtClient.Service/Helpers/DownloadHelper.cs +++ b/server/RdtClient.Service/Helpers/DownloadHelper.cs @@ -28,7 +28,7 @@ public static class DownloadHelper fileName = HttpUtility.UrlDecode(fileName); - fileName = RemoveInvalidFileNameChars(fileName); + fileName = FileHelper.RemoveInvalidFileNameChars(fileName); var filePath = Path.Combine(torrentPath, fileName); @@ -39,9 +39,4 @@ public static class DownloadHelper { return String.Concat(path.Split(Path.GetInvalidPathChars())); } - - private static String RemoveInvalidFileNameChars(String filename) - { - return String.Concat(filename.Split(Path.GetInvalidFileNameChars())); - } } \ No newline at end of file diff --git a/server/RdtClient.Service/Helpers/FileHelper.cs b/server/RdtClient.Service/Helpers/FileHelper.cs index d7cb248..f717073 100644 --- a/server/RdtClient.Service/Helpers/FileHelper.cs +++ b/server/RdtClient.Service/Helpers/FileHelper.cs @@ -73,4 +73,9 @@ public static class FileHelper } } } + + public static String RemoveInvalidFileNameChars(String filename) + { + return String.Concat(filename.Split(Path.GetInvalidFileNameChars())); + } } \ No newline at end of file diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 88193f6..f87d14b 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -142,7 +142,14 @@ public class Torrents Directory.CreateDirectory(Settings.Get.General.CopyAddedTorrents); } - await File.WriteAllTextAsync(Path.Combine(Settings.Get.General.CopyAddedTorrents, $"{torrent.Hash}.magnet"), magnetLink); + var copyFileName = Path.Combine(Settings.Get.General.CopyAddedTorrents, $"{FileHelper.RemoveInvalidFileNameChars(magnet.Name)}.magnet"); + + if (File.Exists(copyFileName)) + { + File.Delete(copyFileName); + } + + await File.WriteAllTextAsync(copyFileName, magnetLink); } catch (Exception ex) { @@ -175,6 +182,8 @@ public class Torrents var newTorrent = await Add(id, hash, fileAsBase64, true, torrent); + Log($"Adding {hash} torrent file", newTorrent); + if (!String.IsNullOrWhiteSpace(Settings.Get.General.CopyAddedTorrents)) { try @@ -184,7 +193,14 @@ public class Torrents Directory.CreateDirectory(Settings.Get.General.CopyAddedTorrents); } - await File.WriteAllBytesAsync(Path.Combine(Settings.Get.General.CopyAddedTorrents, $"{torrent.Hash}.torrent"), bytes); + var copyFileName = Path.Combine(Settings.Get.General.CopyAddedTorrents, $"{FileHelper.RemoveInvalidFileNameChars(monoTorrent.Name)}.torrent"); + + if (File.Exists(copyFileName)) + { + File.Delete(copyFileName); + } + + await File.WriteAllBytesAsync(copyFileName, bytes); } catch (Exception ex) {