mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-06-10 06:45:35 -04:00
combine arr configs #1
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Data.Models.Configuration.QueueCleaner;
|
||||
|
||||
/// <summary>
|
||||
/// Settings for a blocklist
|
||||
/// </summary>
|
||||
[ComplexType]
|
||||
public sealed record BlocklistSettings
|
||||
{
|
||||
public BlocklistType BlocklistType { get; init; }
|
||||
|
||||
public string? BlocklistPath { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Data.Models.Configuration.QueueCleaner;
|
||||
|
||||
public enum BlocklistType
|
||||
{
|
||||
Blacklist,
|
||||
Whitelist
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Data.Models.Configuration.QueueCleaner;
|
||||
|
||||
[ComplexType]
|
||||
public sealed record ContentBlockerConfig
|
||||
{
|
||||
public bool Enabled { get; init; }
|
||||
|
||||
public bool IgnorePrivate { get; init; }
|
||||
|
||||
public bool DeletePrivate { get; init; }
|
||||
|
||||
public BlocklistSettings Sonarr { get; init; } = new();
|
||||
|
||||
public BlocklistSettings Radarr { get; init; } = new();
|
||||
|
||||
public BlocklistSettings Lidarr { get; init; } = new();
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Common.Exceptions;
|
||||
|
||||
namespace Data.Models.Configuration.QueueCleaner;
|
||||
|
||||
[ComplexType]
|
||||
public sealed record FailedImportConfig
|
||||
{
|
||||
public ushort MaxStrikes { get; init; }
|
||||
|
||||
public bool IgnorePrivate { get; init; }
|
||||
|
||||
public bool DeletePrivate { get; init; }
|
||||
|
||||
public IReadOnlyList<string> IgnoredPatterns { get; init; } = [];
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (MaxStrikes is > 0 and < 3)
|
||||
{
|
||||
throw new ValidationException("the minimum value for failed imports max strikes must be 3");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Common.Configuration;
|
||||
|
||||
namespace Data.Models.Configuration.QueueCleaner;
|
||||
|
||||
public sealed record QueueCleanerConfig : IJobConfig
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public Guid Id { get; init; } = Guid.NewGuid();
|
||||
|
||||
public bool Enabled { get; init; }
|
||||
|
||||
public string CronExpression { get; init; } = "0 0/5 * * * ?";
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether to use the CronExpression directly or convert from a user-friendly schedule
|
||||
/// </summary>
|
||||
public bool UseAdvancedScheduling { get; init; } = false;
|
||||
|
||||
public FailedImportConfig FailedImport { get; init; } = new();
|
||||
|
||||
public StalledConfig Stalled { get; init; } = new();
|
||||
|
||||
public SlowConfig Slow { get; init; } = new();
|
||||
|
||||
public ContentBlockerConfig ContentBlocker { get; init; } = new();
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
FailedImport.Validate();
|
||||
Stalled.Validate();
|
||||
Slow.Validate();
|
||||
ContentBlocker.Validate();
|
||||
}
|
||||
}
|
||||
65
code/Data/Models/Configuration/QueueCleaner/SlowConfig.cs
Normal file
65
code/Data/Models/Configuration/QueueCleaner/SlowConfig.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
using Common.CustomDataTypes;
|
||||
using Common.Exceptions;
|
||||
|
||||
namespace Data.Models.Configuration.QueueCleaner;
|
||||
|
||||
[ComplexType]
|
||||
public sealed record SlowConfig
|
||||
{
|
||||
public ushort MaxStrikes { get; init; }
|
||||
|
||||
public bool ResetStrikesOnProgress { get; init; }
|
||||
|
||||
public bool IgnorePrivate { get; init; }
|
||||
|
||||
public bool DeletePrivate { get; init; }
|
||||
|
||||
public string MinSpeed { get; init; } = string.Empty;
|
||||
|
||||
[JsonIgnore]
|
||||
public ByteSize MinSpeedByteSize => string.IsNullOrEmpty(MinSpeed) ? new ByteSize(0) : ByteSize.Parse(MinSpeed);
|
||||
|
||||
public double MaxTime { get; init; }
|
||||
|
||||
public string IgnoreAboveSize { get; init; } = string.Empty;
|
||||
|
||||
[JsonIgnore]
|
||||
public ByteSize? IgnoreAboveSizeByteSize => string.IsNullOrEmpty(IgnoreAboveSize) ? null : ByteSize.Parse(IgnoreAboveSize);
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (MaxStrikes is > 0 and < 3)
|
||||
{
|
||||
throw new ValidationException("the minimum value for slow max strikes must be 3");
|
||||
}
|
||||
|
||||
if (MaxStrikes > 0)
|
||||
{
|
||||
bool isSpeedSet = !string.IsNullOrEmpty(MinSpeed);
|
||||
|
||||
if (isSpeedSet && ByteSize.TryParse(MinSpeed, out _) is false)
|
||||
{
|
||||
throw new ValidationException("invalid value for slow min speed");
|
||||
}
|
||||
|
||||
if (MaxTime < 0)
|
||||
{
|
||||
throw new ValidationException("invalid value for slow max time");
|
||||
}
|
||||
|
||||
if (!isSpeedSet && MaxTime is 0)
|
||||
{
|
||||
throw new ValidationException("either slow min speed or slow max time must be set");
|
||||
}
|
||||
|
||||
bool isIgnoreAboveSizeSet = !string.IsNullOrEmpty(IgnoreAboveSize);
|
||||
|
||||
if (isIgnoreAboveSizeSet && ByteSize.TryParse(IgnoreAboveSize, out _) is false)
|
||||
{
|
||||
throw new ValidationException($"invalid value for slow ignore above size: {IgnoreAboveSize}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
code/Data/Models/Configuration/QueueCleaner/StalledConfig.cs
Normal file
31
code/Data/Models/Configuration/QueueCleaner/StalledConfig.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Common.Exceptions;
|
||||
|
||||
namespace Data.Models.Configuration.QueueCleaner;
|
||||
|
||||
[ComplexType]
|
||||
public sealed record StalledConfig
|
||||
{
|
||||
public ushort MaxStrikes { get; init; }
|
||||
|
||||
public bool ResetStrikesOnProgress { get; init; }
|
||||
|
||||
public bool IgnorePrivate { get; init; }
|
||||
|
||||
public bool DeletePrivate { get; init; }
|
||||
|
||||
public ushort DownloadingMetadataMaxStrikes { get; init; }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (MaxStrikes is > 0 and < 3)
|
||||
{
|
||||
throw new ValidationException("the minimum value for stalled max strikes must be 3");
|
||||
}
|
||||
|
||||
if (DownloadingMetadataMaxStrikes is > 0 and < 3)
|
||||
{
|
||||
throw new ValidationException("the minimum value for downloading metadata max strikes must be 3");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user