Store the torrent name instead of the hash to the blackhole directory.

This commit is contained in:
Roger Far 2024-01-05 10:37:07 -07:00
parent d01cb71866
commit 6ad51b036e
3 changed files with 24 additions and 8 deletions

View file

@ -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()));
}
}

View file

@ -73,4 +73,9 @@ public static class FileHelper
}
}
}
public static String RemoveInvalidFileNameChars(String filename)
{
return String.Concat(filename.Split(Path.GetInvalidFileNameChars()));
}
}

View file

@ -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)
{