diff --git a/code/Data/Models/Configuration/DownloadClientConfig.cs b/code/Data/Models/Configuration/DownloadClientConfig.cs index e49498b7..fa81943e 100644 --- a/code/Data/Models/Configuration/DownloadClientConfig.cs +++ b/code/Data/Models/Configuration/DownloadClientConfig.cs @@ -65,7 +65,7 @@ public sealed record DownloadClientConfig /// [NotMapped] [JsonIgnore] - public Uri Url => new($"{Host?.ToString().TrimEnd('/')}/{UrlBase.TrimStart('/').TrimEnd('/')}"); + public Uri Url => new($"{Host?.ToString().TrimEnd('/')}/{UrlBase?.TrimStart('/').TrimEnd('/')}"); /// /// Validates the configuration diff --git a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceDC.cs b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceDC.cs index 690b74b0..7b7a3229 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceDC.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceDC.cs @@ -69,8 +69,10 @@ public partial class DelugeService { continue; } + + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); - if (!_downloadCleanerConfig.DeletePrivate && download.Private) + if (!downloadCleanerConfig.DeletePrivate && download.Private) { _logger.LogDebug("skip | download is private | {name}", download.Name); continue; @@ -119,10 +121,12 @@ public partial class DelugeService { return; } + + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); - if (!string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir)) + if (!string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir)) { - _hardLinkFileService.PopulateFileCounts(_downloadCleanerConfig.UnlinkedIgnoredRootDir); + _hardLinkFileService.PopulateFileCounts(downloadCleanerConfig.UnlinkedIgnoredRootDir); } foreach (DownloadStatus download in downloads.Cast()) @@ -171,7 +175,7 @@ public partial class DelugeService } long hardlinkCount = _hardLinkFileService - .GetHardLinkCount(filePath, !string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir)); + .GetHardLinkCount(filePath, !string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir)); if (hardlinkCount < 0) { @@ -192,13 +196,13 @@ public partial class DelugeService continue; } - await _dryRunInterceptor.InterceptAsync(ChangeLabel, download.Hash, _downloadCleanerConfig.UnlinkedTargetCategory); + await _dryRunInterceptor.InterceptAsync(ChangeLabel, download.Hash, downloadCleanerConfig.UnlinkedTargetCategory); _logger.LogInformation("category changed for {name}", download.Name); - await _eventPublisher.PublishCategoryChanged(download.Label, _downloadCleanerConfig.UnlinkedTargetCategory); + await _eventPublisher.PublishCategoryChanged(download.Label, downloadCleanerConfig.UnlinkedTargetCategory); - download.Label = _downloadCleanerConfig.UnlinkedTargetCategory; + download.Label = downloadCleanerConfig.UnlinkedTargetCategory; } } diff --git a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceQC.cs b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceQC.cs index 4f10918b..3e600f43 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceQC.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Deluge/DelugeServiceQC.cs @@ -84,12 +84,14 @@ public partial class DelugeService Dictionary? files ) { - if (!_queueCleanerConfig.ContentBlocker.Enabled) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (!queueCleanerConfig.ContentBlocker.Enabled) { return (false, DeleteReason.None); } - if (_queueCleanerConfig.ContentBlocker.IgnorePrivate && isPrivate) + if (queueCleanerConfig.ContentBlocker.IgnorePrivate && isPrivate) { // ignore private trackers _logger.LogDebug("skip unwanted files check | download is private | {name}", download.Name); @@ -187,7 +189,9 @@ public partial class DelugeService private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfSlow(DownloadStatus download) { - if (_queueCleanerConfig.Slow.MaxStrikes is 0) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Slow.MaxStrikes is 0) { return (false, DeleteReason.None); } @@ -202,22 +206,22 @@ public partial class DelugeService return (false, DeleteReason.None); } - if (_queueCleanerConfig.Slow.IgnorePrivate && download.Private) + if (queueCleanerConfig.Slow.IgnorePrivate && download.Private) { // ignore private trackers _logger.LogDebug("skip slow check | download is private | {name}", download.Name); return (false, DeleteReason.None); } - if (download.Size > (_queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue)) + if (download.Size > (queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue)) { _logger.LogDebug("skip slow check | download is too large | {name}", download.Name); return (false, DeleteReason.None); } - ByteSize minSpeed = _queueCleanerConfig.Slow.MinSpeedByteSize; + ByteSize minSpeed = queueCleanerConfig.Slow.MinSpeedByteSize; ByteSize currentSpeed = new ByteSize(download.DownloadSpeed); - SmartTimeSpan maxTime = SmartTimeSpan.FromHours(_queueCleanerConfig.Slow.MaxTime); + SmartTimeSpan maxTime = SmartTimeSpan.FromHours(queueCleanerConfig.Slow.MaxTime); SmartTimeSpan currentTime = SmartTimeSpan.FromSeconds(download.Eta); return await CheckIfSlow( @@ -232,12 +236,14 @@ public partial class DelugeService private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfStuck(DownloadStatus status) { - if (_queueCleanerConfig.Stalled.MaxStrikes is 0) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Stalled.MaxStrikes is 0) { return (false, DeleteReason.None); } - if (_queueCleanerConfig.Stalled.IgnorePrivate && status.Private) + if (queueCleanerConfig.Stalled.IgnorePrivate && status.Private) { // ignore private trackers _logger.LogDebug("skip stalled check | download is private | {name}", status.Name); @@ -256,6 +262,6 @@ public partial class DelugeService ResetStalledStrikesOnProgress(status.Hash!, status.TotalDone); - return (await _striker.StrikeAndCheckLimit(status.Hash!, status.Name!, _queueCleanerConfig.Stalled.MaxStrikes, StrikeType.Stalled), DeleteReason.Stalled); + return (await _striker.StrikeAndCheckLimit(status.Hash!, status.Name!, queueCleanerConfig.Stalled.MaxStrikes, StrikeType.Stalled), DeleteReason.Stalled); } } \ No newline at end of file diff --git a/code/Infrastructure/Verticals/DownloadClient/DownloadService.cs b/code/Infrastructure/Verticals/DownloadClient/DownloadService.cs index 27c13c6b..b19deaf7 100644 --- a/code/Infrastructure/Verticals/DownloadClient/DownloadService.cs +++ b/code/Infrastructure/Verticals/DownloadClient/DownloadService.cs @@ -31,8 +31,6 @@ public abstract class DownloadService : IDownloadService protected readonly IDynamicHttpClientProvider _httpClientProvider; protected readonly EventPublisher _eventPublisher; protected readonly BlocklistProvider _blocklistProvider; - protected readonly QueueCleanerConfig _queueCleanerConfig; - protected readonly DownloadCleanerConfig _downloadCleanerConfig; protected HttpClient? _httpClient; @@ -64,9 +62,6 @@ public abstract class DownloadService : IDownloadService _blocklistProvider = blocklistProvider; _cacheOptions = new MemoryCacheEntryOptions() .SetSlidingExpiration(StaticConfiguration.TriggerValue + Constants.CacheLimitBuffer); - - _queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); - _downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); } /// @@ -117,7 +112,9 @@ public abstract class DownloadService : IDownloadService protected void ResetStalledStrikesOnProgress(string hash, long downloaded) { - if (!_queueCleanerConfig.Stalled.ResetStrikesOnProgress) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (!queueCleanerConfig.Stalled.ResetStrikesOnProgress) { return; } @@ -135,7 +132,9 @@ public abstract class DownloadService : IDownloadService protected void ResetSlowSpeedStrikesOnProgress(string downloadName, string hash) { - if (_queueCleanerConfig.Slow.ResetStrikesOnProgress) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Slow.ResetStrikesOnProgress) { return; } @@ -153,7 +152,9 @@ public abstract class DownloadService : IDownloadService protected void ResetSlowTimeStrikesOnProgress(string downloadName, string hash) { - if (_queueCleanerConfig.Slow.ResetStrikesOnProgress) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Slow.ResetStrikesOnProgress) { return; } @@ -178,12 +179,14 @@ public abstract class DownloadService : IDownloadService SmartTimeSpan currentTime ) { + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + if (minSpeed.Bytes > 0 && currentSpeed < minSpeed) { _logger.LogTrace("slow speed | {speed}/s | {name}", currentSpeed.ToString(), downloadName); bool shouldRemove = await _striker - .StrikeAndCheckLimit(downloadHash, downloadName, _queueCleanerConfig.Slow.MaxStrikes, StrikeType.SlowSpeed); + .StrikeAndCheckLimit(downloadHash, downloadName, queueCleanerConfig.Slow.MaxStrikes, StrikeType.SlowSpeed); if (shouldRemove) { @@ -200,7 +203,7 @@ public abstract class DownloadService : IDownloadService _logger.LogTrace("slow estimated time | {time} | {name}", currentTime.ToString(), downloadName); bool shouldRemove = await _striker - .StrikeAndCheckLimit(downloadHash, downloadName, _queueCleanerConfig.Slow.MaxStrikes, StrikeType.SlowTime); + .StrikeAndCheckLimit(downloadHash, downloadName, queueCleanerConfig.Slow.MaxStrikes, StrikeType.SlowTime); if (shouldRemove) { diff --git a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceDC.cs b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceDC.cs index ec484216..880fbe78 100644 --- a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceDC.cs +++ b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceDC.cs @@ -34,22 +34,27 @@ public partial class QBitService .ToList(); /// - public override List? FilterDownloadsToChangeCategoryAsync(List? downloads, List categories) => - downloads + public override List? FilterDownloadsToChangeCategoryAsync(List? downloads, List categories) + { + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); + + return downloads ?.Cast() .Where(x => !string.IsNullOrEmpty(x.Hash)) .Where(x => categories.Any(cat => cat.Equals(x.Category, StringComparison.InvariantCultureIgnoreCase))) .Where(x => { - if (_downloadCleanerConfig.UnlinkedUseTag) + if (downloadCleanerConfig.UnlinkedUseTag) { - return !x.Tags.Any(tag => tag.Equals(_downloadCleanerConfig.UnlinkedTargetCategory, StringComparison.InvariantCultureIgnoreCase)); + return !x.Tags.Any(tag => + tag.Equals(downloadCleanerConfig.UnlinkedTargetCategory, StringComparison.InvariantCultureIgnoreCase)); } return true; }) .Cast() .ToList(); + } /// public override async Task CleanDownloadsAsync(List? downloads, List categoriesToClean, @@ -94,8 +99,10 @@ public partial class QBitService { continue; } + + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); - if (!_downloadCleanerConfig.DeletePrivate) + if (!downloadCleanerConfig.DeletePrivate) { TorrentProperties? torrentProperties = await _client.GetTorrentPropertiesAsync(download.Hash); @@ -168,10 +175,12 @@ public partial class QBitService { return; } + + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); - if (!string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir)) + if (!string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir)) { - _hardLinkFileService.PopulateFileCounts(_downloadCleanerConfig.UnlinkedIgnoredRootDir); + _hardLinkFileService.PopulateFileCounts(downloadCleanerConfig.UnlinkedIgnoredRootDir); } foreach (TorrentInfo download in downloads) @@ -225,7 +234,7 @@ public partial class QBitService continue; } - long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, !string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir)); + long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, !string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir)); if (hardlinkCount < 0) { @@ -247,19 +256,19 @@ public partial class QBitService continue; } - await _dryRunInterceptor.InterceptAsync(ChangeCategory, download.Hash, _downloadCleanerConfig.UnlinkedTargetCategory); + await _dryRunInterceptor.InterceptAsync(ChangeCategory, download.Hash, downloadCleanerConfig.UnlinkedTargetCategory); - if (_downloadCleanerConfig.UnlinkedUseTag) + if (downloadCleanerConfig.UnlinkedUseTag) { _logger.LogInformation("tag added for {name}", download.Name); } else { _logger.LogInformation("category changed for {name}", download.Name); - download.Category = _downloadCleanerConfig.UnlinkedTargetCategory; + download.Category = downloadCleanerConfig.UnlinkedTargetCategory; } - await _eventPublisher.PublishCategoryChanged(download.Category, _downloadCleanerConfig.UnlinkedTargetCategory, _downloadCleanerConfig.UnlinkedUseTag); + await _eventPublisher.PublishCategoryChanged(download.Category, downloadCleanerConfig.UnlinkedTargetCategory, downloadCleanerConfig.UnlinkedUseTag); } } @@ -294,7 +303,9 @@ public partial class QBitService throw new InvalidOperationException("QBittorrent client is not initialized"); } - if (_downloadCleanerConfig.UnlinkedUseTag) + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); + + if (downloadCleanerConfig.UnlinkedUseTag) { await _client.AddTorrentTagAsync([hash], newCategory); return; diff --git a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceQC.cs b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceQC.cs index ca919ef5..f2247491 100644 --- a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceQC.cs +++ b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitServiceQC.cs @@ -83,12 +83,14 @@ public partial class QBitService IReadOnlyList? files ) { - if (!_queueCleanerConfig.ContentBlocker.Enabled) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (!queueCleanerConfig.ContentBlocker.Enabled) { return (false, DeleteReason.None); } - if (_queueCleanerConfig.ContentBlocker.IgnorePrivate && isPrivate) + if (queueCleanerConfig.ContentBlocker.IgnorePrivate && isPrivate) { // ignore private trackers _logger.LogDebug("skip unwanted files check | download is private | {name}", torrent.Name); @@ -187,7 +189,9 @@ public partial class QBitService private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfSlow(TorrentInfo download, bool isPrivate) { - if (_queueCleanerConfig.Slow.MaxStrikes is 0) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Slow.MaxStrikes is 0) { return (false, DeleteReason.None); } @@ -202,22 +206,22 @@ public partial class QBitService return (false, DeleteReason.None); } - if (_queueCleanerConfig.Slow.IgnorePrivate && isPrivate) + if (queueCleanerConfig.Slow.IgnorePrivate && isPrivate) { // ignore private trackers _logger.LogDebug("skip slow check | download is private | {name}", download.Name); return (false, DeleteReason.None); } - if (download.Size > (_queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue)) + if (download.Size > (queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue)) { _logger.LogDebug("skip slow check | download is too large | {name}", download.Name); return (false, DeleteReason.None); } - ByteSize minSpeed = _queueCleanerConfig.Slow.MinSpeedByteSize; + ByteSize minSpeed = queueCleanerConfig.Slow.MinSpeedByteSize; ByteSize currentSpeed = new ByteSize(download.DownloadSpeed); - SmartTimeSpan maxTime = SmartTimeSpan.FromHours(_queueCleanerConfig.Slow.MaxTime); + SmartTimeSpan maxTime = SmartTimeSpan.FromHours(queueCleanerConfig.Slow.MaxTime); SmartTimeSpan currentTime = new SmartTimeSpan(download.EstimatedTime ?? TimeSpan.Zero); return await CheckIfSlow( @@ -232,7 +236,9 @@ public partial class QBitService private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfStuck(TorrentInfo torrent, bool isPrivate) { - if (_queueCleanerConfig.Stalled.MaxStrikes is 0 && _queueCleanerConfig.Stalled.DownloadingMetadataMaxStrikes is 0) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Stalled.MaxStrikes is 0 && queueCleanerConfig.Stalled.DownloadingMetadataMaxStrikes is 0) { return (false, DeleteReason.None); } @@ -244,9 +250,9 @@ public partial class QBitService return (false, DeleteReason.None); } - if (_queueCleanerConfig.Stalled.MaxStrikes > 0 && torrent.State is TorrentState.StalledDownload) + if (queueCleanerConfig.Stalled.MaxStrikes > 0 && torrent.State is TorrentState.StalledDownload) { - if (_queueCleanerConfig.Stalled.IgnorePrivate && isPrivate) + if (queueCleanerConfig.Stalled.IgnorePrivate && isPrivate) { // ignore private trackers _logger.LogDebug("skip stalled check | download is private | {name}", torrent.Name); @@ -256,15 +262,15 @@ public partial class QBitService ResetStalledStrikesOnProgress(torrent.Hash, torrent.Downloaded ?? 0); return ( - await _striker.StrikeAndCheckLimit(torrent.Hash, torrent.Name, _queueCleanerConfig.Stalled.MaxStrikes, + await _striker.StrikeAndCheckLimit(torrent.Hash, torrent.Name, queueCleanerConfig.Stalled.MaxStrikes, StrikeType.Stalled), DeleteReason.Stalled); } } - if (_queueCleanerConfig.Stalled.DownloadingMetadataMaxStrikes > 0 && torrent.State is not TorrentState.StalledDownload) + if (queueCleanerConfig.Stalled.DownloadingMetadataMaxStrikes > 0 && torrent.State is not TorrentState.StalledDownload) { return ( - await _striker.StrikeAndCheckLimit(torrent.Hash, torrent.Name, _queueCleanerConfig.Stalled.DownloadingMetadataMaxStrikes, + await _striker.StrikeAndCheckLimit(torrent.Hash, torrent.Name, queueCleanerConfig.Stalled.DownloadingMetadataMaxStrikes, StrikeType.DownloadingMetadata), DeleteReason.DownloadingMetadata); } diff --git a/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceDC.cs b/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceDC.cs index 375fdfa9..3b062933 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceDC.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceDC.cs @@ -85,8 +85,10 @@ public partial class TransmissionService { continue; } + + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); - if (!_downloadCleanerConfig.DeletePrivate && download.IsPrivate is true) + if (!downloadCleanerConfig.DeletePrivate && download.IsPrivate is true) { _logger.LogDebug("skip | download is private | {name}", download.Name); continue; @@ -129,9 +131,11 @@ public partial class TransmissionService return; } - if (!string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir)) + var downloadCleanerConfig = ContextProvider.Get(nameof(DownloadCleanerConfig)); + + if (!string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir)) { - _hardLinkFileService.PopulateFileCounts(_downloadCleanerConfig.UnlinkedIgnoredRootDir); + _hardLinkFileService.PopulateFileCounts(downloadCleanerConfig.UnlinkedIgnoredRootDir); } foreach (TorrentInfo download in downloads.Cast()) @@ -176,7 +180,7 @@ public partial class TransmissionService string filePath = string.Join(Path.DirectorySeparatorChar, Path.Combine(download.DownloadDir, file.Name).Split(['\\', '/'])); - long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, !string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir)); + long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, !string.IsNullOrEmpty(downloadCleanerConfig.UnlinkedIgnoredRootDir)); if (hardlinkCount < 0) { @@ -199,13 +203,13 @@ public partial class TransmissionService } string currentCategory = download.GetCategory(); - string newLocation = string.Join(Path.DirectorySeparatorChar, Path.Combine(download.DownloadDir, _downloadCleanerConfig.UnlinkedTargetCategory).Split(['\\', '/'])); + string newLocation = string.Join(Path.DirectorySeparatorChar, Path.Combine(download.DownloadDir, downloadCleanerConfig.UnlinkedTargetCategory).Split(['\\', '/'])); await _dryRunInterceptor.InterceptAsync(ChangeDownloadLocation, download.Id, newLocation); _logger.LogInformation("category changed for {name}", download.Name); - await _eventPublisher.PublishCategoryChanged(currentCategory, _downloadCleanerConfig.UnlinkedTargetCategory); + await _eventPublisher.PublishCategoryChanged(currentCategory, downloadCleanerConfig.UnlinkedTargetCategory); download.DownloadDir = newLocation; } diff --git a/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceQC.cs b/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceQC.cs index a90c71a9..c8211d77 100644 --- a/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceQC.cs +++ b/code/Infrastructure/Verticals/DownloadClient/Transmission/TransmissionServiceQC.cs @@ -78,12 +78,14 @@ public partial class TransmissionService bool isPrivate ) { - if (!_queueCleanerConfig.ContentBlocker.Enabled) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (!queueCleanerConfig.ContentBlocker.Enabled) { return (false, DeleteReason.None); } - if (_queueCleanerConfig.ContentBlocker.IgnorePrivate && isPrivate) + if (queueCleanerConfig.ContentBlocker.IgnorePrivate && isPrivate) { // ignore private trackers _logger.LogDebug("skip unwanted files check | download is private | {name}", download.Name); @@ -179,7 +181,9 @@ public partial class TransmissionService private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfSlow(TorrentInfo download) { - if (_queueCleanerConfig.Slow.MaxStrikes is 0) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Slow.MaxStrikes is 0) { return (false, DeleteReason.None); } @@ -195,22 +199,22 @@ public partial class TransmissionService return (false, DeleteReason.None); } - if (_queueCleanerConfig.Slow.IgnorePrivate && download.IsPrivate is true) + if (queueCleanerConfig.Slow.IgnorePrivate && download.IsPrivate is true) { // ignore private trackers _logger.LogDebug("skip slow check | download is private | {name}", download.Name); return (false, DeleteReason.None); } - if (download.TotalSize > (_queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue)) + if (download.TotalSize > (queueCleanerConfig.Slow.IgnoreAboveSizeByteSize?.Bytes ?? long.MaxValue)) { _logger.LogDebug("skip slow check | download is too large | {name}", download.Name); return (false, DeleteReason.None); } - ByteSize minSpeed = _queueCleanerConfig.Slow.MinSpeedByteSize; + ByteSize minSpeed = queueCleanerConfig.Slow.MinSpeedByteSize; ByteSize currentSpeed = new ByteSize(download.RateDownload ?? long.MaxValue); - SmartTimeSpan maxTime = SmartTimeSpan.FromHours(_queueCleanerConfig.Slow.MaxTime); + SmartTimeSpan maxTime = SmartTimeSpan.FromHours(queueCleanerConfig.Slow.MaxTime); SmartTimeSpan currentTime = SmartTimeSpan.FromSeconds(download.Eta ?? 0); return await CheckIfSlow( @@ -225,7 +229,9 @@ public partial class TransmissionService private async Task<(bool ShouldRemove, DeleteReason Reason)> CheckIfStuck(TorrentInfo download) { - if (_queueCleanerConfig.Stalled.MaxStrikes is 0) + var queueCleanerConfig = ContextProvider.Get(nameof(QueueCleanerConfig)); + + if (queueCleanerConfig.Stalled.MaxStrikes is 0) { return (false, DeleteReason.None); } @@ -241,7 +247,7 @@ public partial class TransmissionService return (false, DeleteReason.None); } - if (_queueCleanerConfig.Stalled.IgnorePrivate && (download.IsPrivate ?? false)) + if (queueCleanerConfig.Stalled.IgnorePrivate && (download.IsPrivate ?? false)) { // ignore private trackers _logger.LogDebug("skip stalled check | download is private | {name}", download.Name); @@ -250,6 +256,6 @@ public partial class TransmissionService ResetStalledStrikesOnProgress(download.HashString!, download.DownloadedEver ?? 0); - return (await _striker.StrikeAndCheckLimit(download.HashString!, download.Name!, _queueCleanerConfig.Stalled.MaxStrikes, StrikeType.Stalled), DeleteReason.Stalled); + return (await _striker.StrikeAndCheckLimit(download.HashString!, download.Name!, queueCleanerConfig.Stalled.MaxStrikes, StrikeType.Stalled), DeleteReason.Stalled); } } \ No newline at end of file