added category change for downloads with no additional hardlinks

This commit is contained in:
Flaminel
2025-02-19 23:46:12 +02:00
parent 5adbdbd920
commit 017e25fb06
27 changed files with 458 additions and 56 deletions
@@ -3,7 +3,7 @@ using Microsoft.Extensions.Configuration;
namespace Common.Configuration.DownloadCleaner;
public sealed record Category : IConfig
public sealed record CleanCategory : IConfig
{
public required string Name { get; init; }
@@ -8,11 +8,17 @@ public sealed record DownloadCleanerConfig : IJobConfig
public const string SectionName = "DownloadCleaner";
public bool Enabled { get; init; }
public List<Category>? Categories { get; init; }
public List<CleanCategory>? Categories { get; init; }
[ConfigurationKeyName("DELETE_PRIVATE")]
public bool DeletePrivate { get; set; }
public bool DeletePrivate { get; init; }
[ConfigurationKeyName("NO_HARDLINKS_CATEGORY")]
public string NoHardlinksCategory { get; init; } = "";
[ConfigurationKeyName("HARDLINK_CATEGORIES")]
public List<string>? HardlinkCategories { get; init; }
public void Validate()
{
@@ -32,5 +38,25 @@ public sealed record DownloadCleanerConfig : IJobConfig
}
Categories?.ForEach(x => x.Validate());
if (string.IsNullOrEmpty(NoHardlinksCategory))
{
return;
}
if (HardlinkCategories?.Count is null or 0)
{
throw new ValidationException("no categories configured");
}
if (HardlinkCategories.Contains(NoHardlinksCategory))
{
throw new ValidationException("NO_HARDLINKS_CATEGORY is present in the list of filtered categories");
}
if (HardlinkCategories.Any(string.IsNullOrEmpty))
{
throw new ValidationException("empty hardlink filter category found");
}
}
}