From a994bc452664699b5bacb4de28cb1e614587a08b Mon Sep 17 00:00:00 2001 From: Flaminel Date: Thu, 27 Feb 2025 21:41:07 +0200 Subject: [PATCH] fixed missing methods --- .../DownloadClient/TestDownloadService.cs | 5 +++-- .../DownloadCleaner/DownloadCleaner.cs | 3 +++ .../DownloadClient/Deluge/DelugeService.cs | 10 +++++++++- .../DownloadClient/DummyDownloadService.cs | 5 +++++ .../Transmission/TransmissionService.cs | 17 +++++++++++++---- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/code/Infrastructure.Tests/Verticals/DownloadClient/TestDownloadService.cs b/code/Infrastructure.Tests/Verticals/DownloadClient/TestDownloadService.cs index de90ddd..fc70bc5 100644 --- a/code/Infrastructure.Tests/Verticals/DownloadClient/TestDownloadService.cs +++ b/code/Infrastructure.Tests/Verticals/DownloadClient/TestDownloadService.cs @@ -42,8 +42,9 @@ public class TestDownloadService : DownloadService ConcurrentBag patterns, ConcurrentBag regexes) => Task.FromResult(new BlockFilesResult()); public override Task DeleteDownload(string hash) => Task.CompletedTask; public override Task CreateCategoryAsync(string name) => Task.CompletedTask; - public override List? FilterDownloadsToBeCleanedAsync(List? downloads, List categories) => Task.FromResult?>(null); - public override List? FilterDownloadsToChangeCategoryAsync(List? downloads, List categories) => Task.FromResult?>(null); + public override Task?> GetSeedingDownloads() => Task.FromResult?>(null); + public override List? FilterDownloadsToBeCleanedAsync(List? downloads, List categories) => null; + public override List? FilterDownloadsToChangeCategoryAsync(List? downloads, List categories) => null; public override Task CleanDownloadsAsync(List? downloads, List categoriesToClean, HashSet excludedHashes) => Task.CompletedTask; public override Task ChangeCategoryForNoHardLinksAsync(List? downloads, HashSet excludedHashes) => Task.CompletedTask; diff --git a/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs b/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs index 44232bb..faa7970 100644 --- a/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs +++ b/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs @@ -89,6 +89,9 @@ public sealed class DownloadCleaner : GenericHandler List? downloadsToClean = _downloadService.FilterDownloadsToBeCleanedAsync(downloads, _config.Categories); + // release unused objects + downloads = null; + _logger.LogTrace("looking for downloads clean"); await _downloadService.CleanDownloadsAsync(downloadsToClean, _config.Categories, _excludedHashes); } diff --git a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs index e7cf2a7..7eba628 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeService.cs @@ -196,11 +196,19 @@ public class DelugeService : DownloadService, IDelugeService return result; } - public override async List? FilterDownloadsToBeCleanedAsync(List? downloads, List categories) + public override async Task?> GetSeedingDownloads() { return (await _client.GetStatusForAllTorrents()) ?.Where(x => !string.IsNullOrEmpty(x.Hash)) .Where(x => x.State?.Equals("seeding", StringComparison.InvariantCultureIgnoreCase) is true) + .Cast() + .ToList(); + } + + public override List? FilterDownloadsToBeCleanedAsync(List? downloads, List categories) + { + return downloads + ?.Cast() .Where(x => categories.Any(cat => cat.Name.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase))) .Cast() .ToList(); diff --git a/code/Infrastructure/Verticals/DownloadClient/DummyDownloadService.cs b/code/Infrastructure/Verticals/DownloadClient/DummyDownloadService.cs index 5d872c3..6e8fc20 100644 --- a/code/Infrastructure/Verticals/DownloadClient/DummyDownloadService.cs +++ b/code/Infrastructure/Verticals/DownloadClient/DummyDownloadService.cs @@ -53,6 +53,11 @@ public class DummyDownloadService : DownloadService throw new NotImplementedException(); } + public override Task?> GetSeedingDownloads() + { + throw new NotImplementedException(); + } + public override List? FilterDownloadsToBeCleanedAsync(List? downloads, List categories) { throw new NotImplementedException(); diff --git a/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionService.cs b/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionService.cs index 59d0854..010439b 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionService.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionService.cs @@ -181,9 +181,8 @@ public class TransmissionService : DownloadService, ITransmissionService return result; } - - /// - public override async List? FilterDownloadsToBeCleanedAsync(List? downloads, List categories) + + public override async Task?> GetSeedingDownloads() { string[] fields = [ TorrentFields.FILES, @@ -199,11 +198,21 @@ public class TransmissionService : DownloadService, ITransmissionService TorrentFields.SECONDS_SEEDING, TorrentFields.UPLOAD_RATIO ]; - + return (await _client.TorrentGetAsync(fields)) ?.Torrents ?.Where(x => !string.IsNullOrEmpty(x.HashString)) .Where(x => x.Status is 5 or 6) + .Cast() + .ToList(); + } + + /// + public override List? FilterDownloadsToBeCleanedAsync(List? downloads, List categories) + { + return downloads + ? + .Cast() .Where(x => categories .Any(cat => {