aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-04-27 18:44:04 -0500
committerJP Dillingham <jp@dillingham.me>2024-04-27 18:44:04 -0500
commit6126fd7508c7ebb503ec29db81eb9e7e17170b71 (patch)
treef4130f6c52cce444321d527e41c31aa5f2d85ab9 /src
parent8c2802cdda09238818b04f51643183c74818b98f (diff)
downloadslskd-6126fd7508c7ebb503ec29db81eb9e7e17170b71.tar.gz
add validation for blacklist format
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Options.cs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index e99eb85f..afc9b07f 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -1106,7 +1106,10 @@ namespace slskd
public bool Swagger { get; init; } = false;
}
- public class BlacklistOptions
+ /// <summary>
+ /// Blacklist options.
+ /// </summary>
+ public class BlacklistOptions : IValidatableObject
{
/// <summary>
/// Gets a value indicating whether blacklist file support should be enabled.
@@ -1125,6 +1128,36 @@ namespace slskd
[Description("path to blacklist file")]
[FileExists(FileAccess.Read)]
public string File { get; init; }
+
+ /// <summary>
+ /// Extended validation.
+ /// </summary>
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ if (!Enabled)
+ {
+ return results;
+ }
+
+ // loading/validating the entire list will be costly on low spec systems
+ // just make sure that we can detect a valid format and leave it at that
+ // if there's a problem with any of the entries, the load will fail and
+ // kill the application
+ try
+ {
+ _ = slskd.Blacklist.DetectFormat(File);
+ }
+ catch (FormatException ex)
+ {
+ results.Add(new ValidationResult(ex.Message));
+ }
+
+ return results;
+ }
}
/// <summary>