diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-08-24 08:14:59 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-08-24 08:14:59 -0500 |
| commit | bc08e38a614eda311f5eca38029816b5fcabc1a5 (patch) | |
| tree | f8495cce07e67f808a02d37ee703cc2202c0f3f5 /src | |
| parent | 0b99e719bee99699376fe7e02bea2c92f3321034 (diff) | |
| download | slskd-bc08e38a614eda311f5eca38029816b5fcabc1a5.tar.gz | |
add Filters options
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Options.cs | 42 |
1 files changed, 41 insertions, 1 deletions
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 @@ -188,6 +188,12 @@ namespace slskd public DirectoriesOptions Directories { get; private set; } = new DirectoriesOptions(); /// <summary> + /// Gets filter options. + /// </summary> + [Validate] + public FiltersOptions Filters { get; private set; } = new FiltersOptions(); + + /// <summary> /// Gets options for the web UI. /// </summary> [Validate] @@ -255,7 +261,7 @@ namespace slskd public string Downloads { get; private set; } = Program.DefaultDownloadsDirectory; /// <summary> - /// Gets the path to shared files. + /// Gets the list of paths to shared files. /// </summary> [Argument('s', "shared")] [EnvironmentVariable("SHARED_DIR")] @@ -340,6 +346,40 @@ namespace slskd } /// <summary> + /// Filter options. + /// </summary> + public class FiltersOptions : IValidatableObject + { + /// <summary> + /// Gets the list of file filters. + /// </summary> + [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<string>(); + + /// <summary> + /// Extended validation. + /// </summary> + /// <param name="validationContext"></param> + /// <returns></returns> + public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) + { + var results = new List<ValidationResult>(); + + foreach (var filter in File) + { + if (!filter.IsValidRegex()) + { + results.Add(new ValidationResult($"File filter '{filter}' is not a valid regular expression")); + } + } + + return results; + } + } + + /// <summary> /// Logger options. /// </summary> public class LoggerOptions |
