diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-05-29 19:08:58 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-05-29 19:08:58 -0500 |
| commit | 040a31783e874c88e0cd35859253e29e33830ecf (patch) | |
| tree | 4da5841a2bf287591c2cf960cc1d86500fd21c55 | |
| parent | 0e4af54cebd4adba3ef32d57f8dbc3920ad28228 (diff) | |
| download | slskd-040a31783e874c88e0cd35859253e29e33830ecf.tar.gz | |
add destination options
| -rw-r--r-- | config/slskd.example.yml | 7 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 63 |
2 files changed, 69 insertions, 1 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 367d8e4d..d295b964 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -39,7 +39,7 @@ # cidr: 0.0.0.0/0,::/0 # permissions: # file: -# mode: ~ # chmod syntax, e.g. 644, 777. not for Windows. +# mode: ~ # chmod syntax, e.g. 644, 777. does nothing on Windows. # directories: # incomplete: ~ # downloads: ~ @@ -78,6 +78,11 @@ # attempts: 3 # delay: 5000 # initial time between retries, in milliseconds # max_delay: 60000 # maximum time between retries, in milliseconds +# destination: +# subdirectory: {SOURCE_DIRECTORY} +# conflict: rename # 'overwrite' or 'rename' +# permissions: +# mode: ~ # chmod syntax, e.g. 644, 777. does nothing on Windows. # groups: # default: # upload: diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index bac86ea2..8123404e 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1029,6 +1029,12 @@ namespace slskd public RetryOptions Retry { get; init; } = new RetryOptions(); /// <summary> + /// Gets download destination options. + /// </summary> + [Validate] + public DestinationOptions Destination { get; init; } = new DestinationOptions(); + + /// <summary> /// Download retry options. /// </summary> public class RetryOptions @@ -1057,6 +1063,63 @@ namespace slskd [Enum(typeof(RetryPartialStrategy))] public string Partial { get; init; } = RetryPartialStrategy.Resume.ToString().ToLowerInvariant(); } + + /// <summary> + /// Download destination options. + /// </summary> + public class DestinationOptions + { + /// <summary> + /// Gets the destination subdirectory for the files in the batch. + /// </summary> + [RelativePath] + [NonTraversingPath] + [String(AllowNull = true, AllowEmpty = false, AllowWhiteSpace = false, MinimumLength = 1)] + public string Subdirectory { get; init; } = "{SOURCE_DIRECTORY}"; + + /// <summary> + /// Gets the strategy for handling conflicting filenames on disk. + /// </summary> + [Enum(typeof(DestinationConflictStrategy))] + public string Conflict { get; init; } = DestinationConflictStrategy.Rename.ToString().ToLowerInvariant(); + + /// <summary> + /// Gets the permissions to apply to downloaded files and directories. + /// </summary> + [Validate] + public DestinationPermissionsOptions Permissions { get; init; } = new DestinationPermissionsOptions(); + + /// <summary> + /// Download destination permission options. + /// </summary> + public class DestinationPermissionsOptions : IValidatableObject + { + /// <summary> + /// Gets the permissions to apply to newly created files. + /// </summary> + /// <remarks> + /// Applicable to non-Windows operating systems, only. + /// </remarks> + public string Mode { get; init; } + + public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) + { + var results = new List<ValidationResult>(); + + if (!string.IsNullOrEmpty(Mode)) + { + var regEx = new Regex("^[0-7]{3,4}$", RegexOptions.Compiled); + + if (!regEx.IsMatch(Mode)) + { + results.Add(new ValidationResult($"Field {nameof(Mode)} is invalid. Specify a three- or four-character string consisting of only 0-7 (chmod syntax, [0]000-[7]777, inclusive)")); + } + } + + return results; + } + } + } } /// <summary> |
