[TB] Add default for fileName in DownloadHelper

This commit is contained in:
Sam Heinz 2024-12-10 15:25:30 +10:00
parent c34c62f879
commit dffce96a45

View file

@ -5,7 +5,7 @@ namespace RdtClient.Service.Helpers;
public static class DownloadHelper
{
public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download, String? fileName)
public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download, String? fileName = null)
{
var fileUrl = download.Link;
@ -19,6 +19,13 @@ public static class DownloadHelper
var uri = new Uri(fileUrl);
var torrentPath = Path.Combine(downloadPath, directory);
if (String.IsNullOrWhiteSpace(fileName))
{
fileName = uri.Segments.Last();
fileName = HttpUtility.UrlDecode(fileName);
}
fileName = FileHelper.RemoveInvalidFileNameChars(fileName);
var matchingTorrentFiles = torrent.Files.Where(m => m.Path.EndsWith(fileName)).Where(m => !String.IsNullOrWhiteSpace(m.Path)).ToList();