diff --git a/server/RdtClient.Data/RdtClient.Data.csproj b/server/RdtClient.Data/RdtClient.Data.csproj index 5172049..1df0e10 100644 --- a/server/RdtClient.Data/RdtClient.Data.csproj +++ b/server/RdtClient.Data/RdtClient.Data.csproj @@ -8,15 +8,15 @@ - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj b/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj index 66981cc..820bb4a 100644 --- a/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj +++ b/server/RdtClient.Service.Test/RdtClient.Service.Test.csproj @@ -15,13 +15,13 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - - + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/server/RdtClient.Service.Test/Services/EnricherTest.cs b/server/RdtClient.Service.Test/Services/EnricherTest.cs index 95a36a8..48d38ae 100644 --- a/server/RdtClient.Service.Test/Services/EnricherTest.cs +++ b/server/RdtClient.Service.Test/Services/EnricherTest.cs @@ -13,7 +13,7 @@ public class EnricherTest : IDisposable public EnricherTest() { - _mockRepository = new MockRepository(MockBehavior.Strict); + _mockRepository = new(MockBehavior.Strict); _loggerMock = _mockRepository.Create>(MockBehavior.Loose); _trackerListGrabberMock = _mockRepository.Create(); } @@ -67,7 +67,7 @@ public class EnricherTest : IDisposable private static BEncodedDictionary CreateTorrentDictWithOnlyAnnounce(String announceUrl) { - return new BEncodedDictionary + return new() { ["announce"] = new BEncodedString(announceUrl), ["info"] = new BEncodedDictionary() @@ -76,7 +76,7 @@ public class EnricherTest : IDisposable private static BEncodedDictionary CreateTorrentDictWithNoTrackers() { - return new BEncodedDictionary + return new() { ["info"] = new BEncodedDictionary() }; diff --git a/server/RdtClient.Service/BackgroundServices/WebsocketsUpdater.cs b/server/RdtClient.Service/BackgroundServices/WebsocketsUpdater.cs index 37cf032..10237d4 100644 --- a/server/RdtClient.Service/BackgroundServices/WebsocketsUpdater.cs +++ b/server/RdtClient.Service/BackgroundServices/WebsocketsUpdater.cs @@ -14,7 +14,9 @@ public class WebsocketsUpdater(ILogger logger, IServiceProvid await Task.Delay(1000, stoppingToken); } - var remoteService = serviceProvider.GetRequiredService(); + var scope = serviceProvider.CreateScope(); + + var remoteService = scope.ServiceProvider.GetRequiredService(); while (!stoppingToken.IsCancellationRequested) { diff --git a/server/RdtClient.Service/RdtClient.Service.csproj b/server/RdtClient.Service/RdtClient.Service.csproj index 72990be..21b33fa 100644 --- a/server/RdtClient.Service/RdtClient.Service.csproj +++ b/server/RdtClient.Service/RdtClient.Service.csproj @@ -12,20 +12,20 @@ - - - - + + + + - + - + - + - - + + diff --git a/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs b/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs index b62b925..cb2e112 100644 --- a/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs @@ -32,7 +32,7 @@ public class BezzadDownloader : IDownloader // For all options, see https://github.com/bezzad/Downloader _downloadConfiguration = new() { - MaxTryAgainOnFailover = 5, + MaxTryAgainOnFailure = 5, RangeDownload = false, ClearPackageOnCompletionWithFailure = true, ReserveStorageSpaceBeforeStartingDownload = false, diff --git a/server/RdtClient.Service/Services/Enricher.cs b/server/RdtClient.Service/Services/Enricher.cs index 64a2965..a79c67d 100644 --- a/server/RdtClient.Service/Services/Enricher.cs +++ b/server/RdtClient.Service/Services/Enricher.cs @@ -76,14 +76,14 @@ public sealed class Enricher(ILogger logger, ITrackerListGrabber track if (!paramDict.ContainsKey(key)) { - paramDict[key] = new List(); + paramDict[key] = []; } paramDict[key].AddRange(queryKVs.GetValues(key) ?? []); } var existingTrackers = paramDict.TryGetValue("tr", out var value) - ? new HashSet(value, StringComparer.OrdinalIgnoreCase) + ? new(value, StringComparer.OrdinalIgnoreCase) : new HashSet(StringComparer.OrdinalIgnoreCase); paramDict.Remove("tr"); diff --git a/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs index 7b3890a..f5b2289 100644 --- a/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs @@ -128,14 +128,18 @@ public class RealDebridTorrentClient(ILogger logger, IH public async Task AddMagnet(String magnetLink) { - var result = await GetClient().Torrents.AddMagnetAsync(magnetLink); + var timeoutCancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(Settings.Get.Provider.Timeout)); + + var result = await GetClient().Torrents.AddMagnetAsync(magnetLink, timeoutCancellationToken.Token); return result.Id; } public async Task AddFile(Byte[] bytes) { - var result = await GetClient().Torrents.AddFileAsync(bytes); + var timeoutCancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(Settings.Get.Provider.Timeout)); + + var result = await GetClient().Torrents.AddFileAsync(bytes, timeoutCancellationToken.Token); return result.Id; } diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index e7ba302..8c84ed5 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -217,16 +217,16 @@ public class TorrentRunner(ILogger logger, Torrents torrents, Dow Log($"Unpack reported an error: {unpackClient.Error}", download, download.Torrent); await downloads.UpdateError(downloadId, unpackClient.Error); - await downloads.UpdateCompleted(downloadId, DateTimeOffset.UtcNow); } else { Log($"Unpack finished successfully", download, download.Torrent); await downloads.UpdateUnpackingFinished(downloadId, DateTimeOffset.UtcNow); - await downloads.UpdateCompleted(downloadId, DateTimeOffset.UtcNow); } + await downloads.UpdateCompleted(downloadId, DateTimeOffset.UtcNow); + ActiveUnpackClients.TryRemove(downloadId, out _); Log($"Removed from ActiveUnpackClients", download, download.Torrent); diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 8d4be9b..c1ec313 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -3,7 +3,6 @@ using System.IO.Abstractions; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; -using System.Web; using Microsoft.Extensions.Logging; using MonoTorrent; using RdtClient.Data.Data; diff --git a/server/RdtClient.Service/Services/TrackerListGrabber.cs b/server/RdtClient.Service/Services/TrackerListGrabber.cs index 7e49b32..88b560f 100644 --- a/server/RdtClient.Service/Services/TrackerListGrabber.cs +++ b/server/RdtClient.Service/Services/TrackerListGrabber.cs @@ -1,4 +1,3 @@ -using System.Net.Http.Headers; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using System.Reflection; @@ -96,7 +95,7 @@ public class TrackerListGrabber(IHttpClientFactory httpClientFactory, IMemoryCac { logger.LogError(ex, "Unable to fetch tracker list."); - throw new Exception("Unable to fetch tracker list for enrichment.", ex); + throw new("Unable to fetch tracker list for enrichment.", ex); } finally { @@ -116,7 +115,7 @@ public class TrackerListGrabber(IHttpClientFactory httpClientFactory, IMemoryCac ? $"v{version[..version.LastIndexOf('.')]}" : ""; - httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("RdtClient", currentVersion)); + httpClient.DefaultRequestHeaders.UserAgent.Add(new("RdtClient", currentVersion)); using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(15)); var token = cts.Token; var response = await httpClient.GetAsync(trackerUri, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false); diff --git a/server/RdtClient.Web/RdtClient.Web.csproj b/server/RdtClient.Web/RdtClient.Web.csproj index 1335563..10c5c95 100644 --- a/server/RdtClient.Web/RdtClient.Web.csproj +++ b/server/RdtClient.Web/RdtClient.Web.csproj @@ -30,16 +30,16 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + +