rdt-client/server/RdtClient.Service/Helpers/DownloadHelper.cs
2022-05-13 18:51:04 -06:00

33 lines
No EOL
809 B
C#

using System.Web;
using RdtClient.Data.Models.Data;
namespace RdtClient.Service.Helpers;
public static class DownloadHelper
{
public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download)
{
var fileUrl = download.Link;
if (String.IsNullOrWhiteSpace(fileUrl) || torrent.RdName == null)
{
return null;
}
var uri = new Uri(fileUrl);
var torrentPath = Path.Combine(downloadPath, torrent.RdName);
if (!Directory.Exists(torrentPath))
{
Directory.CreateDirectory(torrentPath);
}
var fileName = uri.Segments.Last();
fileName = HttpUtility.UrlDecode(fileName);
var filePath = Path.Combine(torrentPath, fileName);
return filePath;
}
}