fixed categories not being filtered when fetching downloads; fixed inconsistent var naming

This commit is contained in:
Flaminel
2025-02-22 02:27:48 +02:00
parent bd81f2ffca
commit c65c85a0c5
4 changed files with 22 additions and 17 deletions
@@ -15,13 +15,13 @@ public sealed record DownloadCleanerConfig : IJobConfig
public bool DeletePrivate { get; init; } public bool DeletePrivate { get; init; }
[ConfigurationKeyName("NO_HL_CATEGORY")] [ConfigurationKeyName("NO_HL_CATEGORY")]
public string NoHardlinksCategory { get; init; } = ""; public string NoHardLinksCategory { get; init; } = "";
[ConfigurationKeyName("NO_HL_IGNORE_ROOT_DIR")] [ConfigurationKeyName("NO_HL_IGNORE_ROOT_DIR")]
public bool IgnoreRootDir { get; init; } public bool NoHardLinksIgnoreRootDir { get; init; }
[ConfigurationKeyName("NO_HL_CATEGORIES")] [ConfigurationKeyName("NO_HL_CATEGORIES")]
public List<string>? HardlinkCategories { get; init; } public List<string>? NoHardLinksCategories { get; init; }
public void Validate() public void Validate()
{ {
@@ -42,22 +42,22 @@ public sealed record DownloadCleanerConfig : IJobConfig
Categories?.ForEach(x => x.Validate()); Categories?.ForEach(x => x.Validate());
if (string.IsNullOrEmpty(NoHardlinksCategory)) if (string.IsNullOrEmpty(NoHardLinksCategory))
{ {
return; return;
} }
if (HardlinkCategories?.Count is null or 0) if (NoHardLinksCategories?.Count is null or 0)
{ {
throw new ValidationException("no categories configured"); throw new ValidationException("no categories configured");
} }
if (HardlinkCategories.Contains(NoHardlinksCategory)) if (NoHardLinksCategories.Contains(NoHardLinksCategory))
{ {
throw new ValidationException("NO_HARDLINKS_CATEGORY is present in the list of filtered categories"); throw new ValidationException("NO_HARDLINKS_CATEGORY is present in the list of filtered categories");
} }
if (HardlinkCategories.Any(string.IsNullOrEmpty)) if (NoHardLinksCategories.Any(string.IsNullOrEmpty))
{ {
throw new ValidationException("empty hardlink filter category found"); throw new ValidationException("empty hardlink filter category found");
} }
@@ -65,18 +65,18 @@ public sealed class DownloadCleaner : GenericHandler
List<object>? downloadsToBeCleaned = await _downloadService.GetDownloadsToBeCleanedAsync(_config.Categories); List<object>? downloadsToBeCleaned = await _downloadService.GetDownloadsToBeCleanedAsync(_config.Categories);
List<object>? downloadsToChangeCategory = null; List<object>? downloadsToChangeCategory = null;
if (!string.IsNullOrEmpty(_config.NoHardlinksCategory) && _config.HardlinkCategories?.Count > 0) if (!string.IsNullOrEmpty(_config.NoHardLinksCategory) && _config.NoHardLinksCategories?.Count > 0)
{ {
if (!_hardLinkCategoryCreated) if (!_hardLinkCategoryCreated)
{ {
_logger.LogTrace("creating category {cat}", _config.NoHardlinksCategory); _logger.LogTrace("creating category {cat}", _config.NoHardLinksCategory);
await _downloadService.CreateCategoryAsync(_config.NoHardlinksCategory); await _downloadService.CreateCategoryAsync(_config.NoHardLinksCategory);
_hardLinkCategoryCreated = true; _hardLinkCategoryCreated = true;
} }
_logger.LogTrace("getting downloads to change category"); _logger.LogTrace("getting downloads to change category");
downloadsToChangeCategory = await _downloadService.GetDownloadsToChangeCategoryAsync(_config.HardlinkCategories); downloadsToChangeCategory = await _downloadService.GetDownloadsToChangeCategoryAsync(_config.NoHardLinksCategories);
} }
bool hasDownloadsToClean = downloadsToBeCleaned?.Count > 0; bool hasDownloadsToClean = downloadsToBeCleaned?.Count > 0;
@@ -226,6 +226,7 @@ public class QBitService : DownloadService, IQBitService
Filter = TorrentListFilter.Seeding Filter = TorrentListFilter.Seeding
})) }))
?.Where(x => !string.IsNullOrEmpty(x.Hash)) ?.Where(x => !string.IsNullOrEmpty(x.Hash))
.Where(x => categories.Any(cat => cat.Equals(x.Category, StringComparison.InvariantCultureIgnoreCase)))
.Cast<object>() .Cast<object>()
.ToList(); .ToList();
} }
@@ -313,7 +314,7 @@ public class QBitService : DownloadService, IQBitService
public override async Task ChangeCategoryForNoHardLinksAsync(List<object> downloads, HashSet<string> excludedHashes) public override async Task ChangeCategoryForNoHardLinksAsync(List<object> downloads, HashSet<string> excludedHashes)
{ {
if (_downloadCleanerConfig.IgnoreRootDir) if (_downloadCleanerConfig.NoHardLinksIgnoreRootDir)
{ {
downloads downloads
.Cast<TorrentInfo>() .Cast<TorrentInfo>()
@@ -365,6 +366,8 @@ public class QBitService : DownloadService, IQBitService
continue; continue;
} }
ContextProvider.Set("downloadName", download.Name);
ContextProvider.Set("hash", download.Hash);
bool hasHardlinks = false; bool hasHardlinks = false;
foreach (TorrentContent file in files) foreach (TorrentContent file in files)
@@ -380,7 +383,7 @@ public class QBitService : DownloadService, IQBitService
: download.SavePath, file.Name : download.SavePath, file.Name
); );
long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, _downloadCleanerConfig.IgnoreRootDir); long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, _downloadCleanerConfig.NoHardLinksIgnoreRootDir);
if (hardlinkCount < 0) if (hardlinkCount < 0)
{ {
@@ -403,8 +406,8 @@ public class QBitService : DownloadService, IQBitService
_logger.LogInformation("changing category for {name}", download.Name); _logger.LogInformation("changing category for {name}", download.Name);
await ((QBitService)Proxy).ChangeCategory(download.Hash, _downloadCleanerConfig.NoHardlinksCategory); await ((QBitService)Proxy).ChangeCategory(download.Hash, _downloadCleanerConfig.NoHardLinksCategory);
await _notifier.NotifyCategoryChanged(download.Category, _downloadCleanerConfig.NoHardlinksCategory); await _notifier.NotifyCategoryChanged(download.Category, _downloadCleanerConfig.NoHardLinksCategory);
} }
} }
+4 -2
View File
@@ -215,8 +215,10 @@ services:
- DOWNLOADCLEANER__CATEGORIES__1__MIN_SEED_TIME=0 - DOWNLOADCLEANER__CATEGORIES__1__MIN_SEED_TIME=0
- DOWNLOADCLEANER__CATEGORIES__1__MAX_SEED_TIME=-1 - DOWNLOADCLEANER__CATEGORIES__1__MAX_SEED_TIME=-1
- DOWNLOADCLEANER__HARDLINK_CATEGORIES__0=tv-sonarr - DOWNLOADCLEANER__NO_HL_CATEGORY=nohardlink
- DOWNLOADCLEANER__HARDLINK_CATEGORIES__1=radarr - DOWNLOADCLEANER__NO_HL_IGNORE_ROOT_DIR=true
- DOWNLOADCLEANER__NO_HL_CATEGORIES__0=tv-sonarr
- DOWNLOADCLEANER__NO_HL_CATEGORIES__1=radarr
- DOWNLOAD_CLIENT=qbittorrent - DOWNLOAD_CLIENT=qbittorrent
- QBITTORRENT__URL=http://qbittorrent:8080 - QBITTORRENT__URL=http://qbittorrent:8080