diff --git a/server/RdtClient.Data/Data/TorrentData.cs b/server/RdtClient.Data/Data/TorrentData.cs index 63d6cf6..34f43a3 100644 --- a/server/RdtClient.Data/Data/TorrentData.cs +++ b/server/RdtClient.Data/Data/TorrentData.cs @@ -51,12 +51,12 @@ public class TorrentData(DataContext dataContext) public async Task GetByHash(String hash) { -#pragma warning disable CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons + hash = hash.ToLower(); + var dbTorrent = await dataContext.Torrents .AsNoTracking() .Include(m => m.Downloads) - .FirstOrDefaultAsync(m => m.Hash.ToLower() == hash.ToLower()); -#pragma warning restore CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons + .FirstOrDefaultAsync(m => m.Hash == hash); if (dbTorrent == null) { diff --git a/server/RdtClient.Data/RdtClient.Data.csproj b/server/RdtClient.Data/RdtClient.Data.csproj index 81e9430..ff4da08 100644 --- a/server/RdtClient.Data/RdtClient.Data.csproj +++ b/server/RdtClient.Data/RdtClient.Data.csproj @@ -1,22 +1,22 @@ - net8.0 + net9.0 enable enable latest - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/server/RdtClient.Service/Helpers/DownloadHelper.cs b/server/RdtClient.Service/Helpers/DownloadHelper.cs index c427ac1..bbb1775 100644 --- a/server/RdtClient.Service/Helpers/DownloadHelper.cs +++ b/server/RdtClient.Service/Helpers/DownloadHelper.cs @@ -1,14 +1,11 @@ -using System; -using System.Web; -using RdtClient.Data.Enums; +using System.Web; using RdtClient.Data.Models.Data; -using RdtClient.Service.Services; namespace RdtClient.Service.Helpers; public static class DownloadHelper { - public static async Task GetDownloadPath(String downloadPath, Torrent torrent, Download download) + public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download) { var fileUrl = download.Link; @@ -24,20 +21,6 @@ public static class DownloadHelper var fileName = uri.Segments.Last(); - if (Settings.Get.Provider.Provider == Provider.TorBox) - { - using (HttpClient client = new HttpClient()) - { - HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, uri); - HttpResponseMessage response = await client.SendAsync(request); - - if (response.Content.Headers.ContentDisposition != null) - { - fileName = response.Content.Headers.ContentDisposition.FileName!.Trim('"'); - } - } - } - fileName = HttpUtility.UrlDecode(fileName); fileName = FileHelper.RemoveInvalidFileNameChars(fileName); @@ -68,7 +51,7 @@ public static class DownloadHelper return filePath; } - public static async Task GetDownloadPath(Torrent torrent, Download download) + public static String? GetDownloadPath(Torrent torrent, Download download) { var fileUrl = download.Link; @@ -82,20 +65,6 @@ public static class DownloadHelper var fileName = uri.Segments.Last(); - if (Settings.Get.Provider.Provider == Provider.TorBox) - { - using (HttpClient client = new HttpClient()) - { - HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, uri); - HttpResponseMessage response = await client.SendAsync(request); - - if (response.Content.Headers.ContentDisposition != null) - { - fileName = response.Content.Headers.ContentDisposition.FileName!.Trim('"'); - } - } - } - fileName = HttpUtility.UrlDecode(fileName); fileName = FileHelper.RemoveInvalidFileNameChars(fileName); diff --git a/server/RdtClient.Service/RdtClient.Service.csproj b/server/RdtClient.Service/RdtClient.Service.csproj index ae30459..46e3a0f 100644 --- a/server/RdtClient.Service/RdtClient.Service.csproj +++ b/server/RdtClient.Service/RdtClient.Service.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 enable enable latest @@ -11,15 +11,15 @@ - + - - + + - + - + diff --git a/server/RdtClient.Service/Services/DownloadClient.cs b/server/RdtClient.Service/Services/DownloadClient.cs index d5faf3d..3ab400b 100644 --- a/server/RdtClient.Service/Services/DownloadClient.cs +++ b/server/RdtClient.Service/Services/DownloadClient.cs @@ -43,15 +43,15 @@ public class DownloadClient(Download download, Torrent torrent, String destinati if (Type != Data.Enums.DownloadClient.Symlink) { - await FileHelper.Delete(filePath.Result!); + await FileHelper.Delete(filePath); } Downloader = Type switch { - Data.Enums.DownloadClient.Internal => new InternalDownloader(download.Link, filePath.Result!), - Data.Enums.DownloadClient.Bezzad => new BezzadDownloader(download.Link, filePath.Result!), - Data.Enums.DownloadClient.Aria2c => new Aria2cDownloader(download.RemoteId, download.Link, filePath.Result!, downloadPath.Result!, category), - Data.Enums.DownloadClient.Symlink => new SymlinkDownloader(download.Link, filePath.Result!, downloadPath.Result!), + Data.Enums.DownloadClient.Internal => new InternalDownloader(download.Link, filePath), + Data.Enums.DownloadClient.Bezzad => new BezzadDownloader(download.Link, filePath), + Data.Enums.DownloadClient.Aria2c => new Aria2cDownloader(download.RemoteId, download.Link, filePath, downloadPath, category), + Data.Enums.DownloadClient.Symlink => new SymlinkDownloader(download.Link, filePath, downloadPath), _ => throw new($"Unknown download client {Type}") }; diff --git a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs index 74408b5..11e02da 100644 --- a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs @@ -138,7 +138,7 @@ public class InternalDownloader : IDownloader { settingDownloadMaxSpeed = 0; } - settingDownloadMaxSpeed = settingDownloadMaxSpeed / Math.Max(TorrentRunner.ActiveDownloadClients.Count, 1); + settingDownloadMaxSpeed /= Math.Max(TorrentRunner.ActiveDownloadClients.Count, 1); settingDownloadMaxSpeed = settingDownloadMaxSpeed * 1024 * 1024; var settingDownloadTimeout = Settings.Get.DownloadClient.Timeout; diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 8ed91e9..b7a9407 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -3,7 +3,6 @@ using Newtonsoft.Json; using TorBoxNET; using RdtClient.Data.Enums; using RdtClient.Data.Models.TorrentClient; -using RdtClient.Service.Helpers; namespace RdtClient.Service.Services.TorrentClients; @@ -74,9 +73,9 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien Progress = (Int64)((torrent.Progress) * 100.0), Status = torrent.DownloadState, Added = ChangeTimeZone(torrent.CreatedAt)!.Value, - Files = (torrent.Files ?? []).Select(m => new TorrentClientFile + Files = torrent.Files.Select(m => new TorrentClientFile { - Path = string.Join("/", m.Name.Split('/').Skip(1)), + Path = String.Join("/", m.Name.Split('/').Skip(1)), Bytes = m.Size, Id = m.Id, Selected = true @@ -104,7 +103,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien torrents.AddRange(queuedTorrents); } - return torrents!.Select(Map).ToList(); + return torrents.Select(Map).ToList(); } public async Task GetUser() @@ -141,26 +140,20 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien public async Task AddFile(Byte[] bytes) { - var seeding = Settings.Get.Integrations.Default.FinishedAction; - // Line is not working right now, will disable seeding and fix in december when I have time again. // var seed = (seeding == TorrentFinishedAction.RemoveAllTorrents || seeding == TorrentFinishedAction.RemoveRealDebrid) ? 3 : 2; + const Int32 seed = 3; - var seed = 3; - - var result = await GetClient().Torrents.AddFileAsync(bytes, seed, false); + var result = await GetClient().Torrents.AddFileAsync(bytes, seed); if (result.Error == "ACTIVE_LIMIT") { - using (var stream = new MemoryStream(bytes)) - { - var torrent = MonoTorrent.Torrent.Load(stream); - return torrent!.InfoHashes.V1!.ToHex().ToLowerInvariant(); - } - } - else - { - return result.Data!.Hash!; + using var stream = new MemoryStream(bytes); + + var torrent = await MonoTorrent.Torrent.LoadAsync(stream); + return torrent.InfoHashes.V1!.ToHex().ToLowerInvariant(); } + + return result.Data!.Hash!; } public async Task> GetAvailableFiles(String hash) @@ -169,24 +162,15 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien if (availability.Data != null) { - var availableFiles = new List(); - foreach (var file in availability.Data[0]?.Files!) - { - availableFiles.Add( - new TorrentClientAvailableFile - { - Filename = file!.Name, - Filesize = file.Size - }); - } - return availableFiles; - } - else - { - return []; + return (availability.Data[0]?.Files ?? []).Select(file => new TorrentClientAvailableFile() + { + Filename = file.Name, + Filesize = file.Size + }) + .ToList(); } - + return []; } public Task SelectFiles(Data.Models.Data.Torrent torrent) @@ -199,21 +183,21 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien await GetClient().Torrents.ControlAsync(torrentId, "delete"); } - public async Task Unrestrict(string link) + public async Task Unrestrict(String link) { var segments = link.Split('/'); - bool zipped = segments[5] == "zip"; - string fileId = zipped ? "0" : segments[5]; + var zipped = segments[5] == "zip"; + var fileId = zipped ? "0" : segments[5]; var result = await GetClient().Torrents.RequestDownloadAsync(Convert.ToInt32(segments[4]), Convert.ToInt32(fileId), zipped); - if (result?.Error != null) + if (result.Error != null) { throw new("Unrestrict returned an invalid download"); } - return result!.Data!; + return result.Data!; } public async Task UpdateData(Data.Models.Data.Torrent torrent, TorrentClientTorrent? torrentClientTorrent) @@ -303,12 +287,6 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien public async Task?> GetDownloadLinks(Data.Models.Data.Torrent torrent) { - if (torrent.Hash == null) - { - return null; - } - - var rdTorrent = await GetInfo(torrent.Hash); var files = new List(); var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 4885e1b..25817cf 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -553,7 +553,7 @@ public class Torrents( { Log($"Deleting {filePath}", download, download.Torrent); - await FileHelper.Delete(filePath.Result!); + await FileHelper.Delete(filePath); } Log($"Resetting", download, download.Torrent); diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index c702d71..2724f43 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -31,7 +31,7 @@ public class UnpackClient(Download download, String destinationPath) { if (!_cancellationTokenSource.IsCancellationRequested) { - await Unpack(filePath.Result!, _cancellationTokenSource.Token); + await Unpack(filePath, _cancellationTokenSource.Token); } }); } diff --git a/server/RdtClient.Web/Controllers/QBittorrentController.cs b/server/RdtClient.Web/Controllers/QBittorrentController.cs index a527f7b..fe162b2 100644 --- a/server/RdtClient.Web/Controllers/QBittorrentController.cs +++ b/server/RdtClient.Web/Controllers/QBittorrentController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using RdtClient.Data.Enums; using RdtClient.Data.Models.QBittorrent; using RdtClient.Service.Services; diff --git a/server/RdtClient.Web/Program.cs b/server/RdtClient.Web/Program.cs index e65ad0c..d1d676a 100644 --- a/server/RdtClient.Web/Program.cs +++ b/server/RdtClient.Web/Program.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using System.Net; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Hosting.WindowsServices; @@ -136,8 +135,6 @@ builder.Host.UseWindowsService(); RdtClient.Data.DiConfig.Config(builder.Services, appSettings); builder.Services.RegisterRdtServices(); -ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - try { // Build the app diff --git a/server/RdtClient.Web/RdtClient.Web.csproj b/server/RdtClient.Web/RdtClient.Web.csproj index 9de70e8..032a8b0 100644 --- a/server/RdtClient.Web/RdtClient.Web.csproj +++ b/server/RdtClient.Web/RdtClient.Web.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 Exe 94c24cba-f03f-4453-a671-3640b517c573 2.0.86 @@ -29,17 +29,17 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/server/RdtClient.sln.DotSettings b/server/RdtClient.sln.DotSettings index b248b47..46b2271 100644 --- a/server/RdtClient.sln.DotSettings +++ b/server/RdtClient.sln.DotSettings @@ -199,10 +199,12 @@ <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True True True True True True True + True \ No newline at end of file