From bc08e38a614eda311f5eca38029816b5fcabc1a5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 24 Aug 2021 08:14:59 -0500 Subject: add Filters options --- src/slskd/Options.cs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index ec1eab06..fb4ec087 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -187,6 +187,12 @@ namespace slskd [RequiresRestart] public DirectoriesOptions Directories { get; private set; } = new DirectoriesOptions(); + /// + /// Gets filter options. + /// + [Validate] + public FiltersOptions Filters { get; private set; } = new FiltersOptions(); + /// /// Gets options for the web UI. /// @@ -255,7 +261,7 @@ namespace slskd public string Downloads { get; private set; } = Program.DefaultDownloadsDirectory; /// - /// Gets the path to shared files. + /// Gets the list of paths to shared files. /// [Argument('s', "shared")] [EnvironmentVariable("SHARED_DIR")] @@ -339,6 +345,40 @@ namespace slskd public bool Swagger { get; private set; } = false; } + /// + /// Filter options. + /// + public class FiltersOptions : IValidatableObject + { + /// + /// Gets the list of file filters. + /// + [Argument(default, "file-filter")] + [EnvironmentVariable("FILE_FILTER")] + [Description("regular expressions to filter files from shares and results")] + public string[] File { get; private set; } = Array.Empty(); + + /// + /// Extended validation. + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + foreach (var filter in File) + { + if (!filter.IsValidRegex()) + { + results.Add(new ValidationResult($"File filter '{filter}' is not a valid regular expression")); + } + } + + return results; + } + } + /// /// Logger options. /// -- cgit v1.2.3