aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-02 08:26:14 -0500
committerGitHub <noreply@github.com>2021-07-02 08:26:14 -0500
commit6e4166314c7cb9ce51f5c6ecff72258be26524b0 (patch)
tree3f67ea09cfb52e4108bf2f00dc8b40744b66964e /src/slskd/Options.cs
parent2ea8ed330d13c972c4cc36b13327701e6f4762d9 (diff)
parent32cd804dd3e13967a14316ae76ae2ce71c3de936 (diff)
downloadslskd-6e4166314c7cb9ce51f5c6ecff72258be26524b0.tar.gz
Merge pull request #109 from slskd/ftp
Add the ability to upload files to an FTP after downloads complete
Diffstat (limited to 'src/slskd/Options.cs')
-rw-r--r--src/slskd/Options.cs130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs
index 485619bc..f8190fc7 100644
--- a/src/slskd/Options.cs
+++ b/src/slskd/Options.cs
@@ -18,9 +18,11 @@
namespace slskd
{
using System;
+ using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
+ using FluentFTP;
using slskd.Validation;
using Soulseek.Diagnostics;
using Utility.CommandLine;
@@ -122,6 +124,12 @@ namespace slskd
public SoulseekOptions Soulseek { get; private set; } = new SoulseekOptions();
/// <summary>
+ /// Gets options for external integrations.
+ /// </summary>
+ [Validate]
+ public IntegrationOptions Integration { get; private set; } = new IntegrationOptions();
+
+ /// <summary>
/// Directory options.
/// </summary>
public class DirectoriesOptions
@@ -547,5 +555,127 @@ namespace slskd
}
}
}
+
+ /// <summary>
+ /// Options for external integrations.
+ /// </summary>
+ public class IntegrationOptions
+ {
+ /// <summary>
+ /// Gets FTP options.
+ /// </summary>
+ [Validate]
+ public FTPOptions FTP { get; private set; } = new FTPOptions();
+
+ /// <summary>
+ /// FTP options.
+ /// </summary>
+ public class FTPOptions : IValidatableObject
+ {
+ /// <summary>
+ /// Gets a value indicating whether the FTP integration is enabled.
+ /// </summary>
+ [Argument(default, "ftp")]
+ [EnvironmentVariable("FTP_ENABLED")]
+ [Description("enable FTP integration")]
+ public bool Enabled { get; private set; }
+
+ /// <summary>
+ /// Gets the FTP address.
+ /// </summary>
+ [Argument(default, "ftp-address")]
+ [EnvironmentVariable("FTP_ADDRESS")]
+ [Description("FTP address")]
+ public string Address { get; private set; }
+
+ /// <summary>
+ /// Gets the FTP port.
+ /// </summary>
+ [Argument(default, "ftp-port")]
+ [EnvironmentVariable("FTP_PORT")]
+ [Description("FTP port")]
+ [Range(1, 65535)]
+ public int Port { get; private set; } = 21;
+
+ /// <summary>
+ /// Gets the FTP encryption mode.
+ /// </summary>
+ [Argument(default, "ftp-encryption-mode")]
+ [EnvironmentVariable("FTP_ENCRYPTION_MODE")]
+ [Description("FTP encryption mode; none, implicit, explicit, auto")]
+ [Enum(typeof(FtpEncryptionMode))]
+ public string EncryptionMode { get; private set; } = "auto";
+
+ /// <summary>
+ /// Gets a value indicating whether FTP certificate errors should be ignored.
+ /// </summary>
+ [Argument(default, "ftp-ignore-certificate-errors")]
+ [EnvironmentVariable("FTP_IGNORE_CERTIFICATE_ERRORS")]
+ [Description("ignore FTP certificate errors")]
+ public bool IgnoreCertificateErrors { get; private set; } = false;
+
+ /// <summary>
+ /// Gets the FTP username.
+ /// </summary>
+ [Argument(default, "ftp-username")]
+ [EnvironmentVariable("FTP_USERNAME")]
+ [Description("FTP username")]
+ public string Username { get; private set; }
+
+ /// <summary>
+ /// Gets the FTP password.
+ /// </summary>
+ [Argument(default, "ftp-password")]
+ [EnvironmentVariable("FTP_PASSWORD")]
+ [Description("FTP password")]
+ public string Password { get; private set; }
+
+ /// <summary>
+ /// Gets the remote path for uploads.
+ /// </summary>
+ [Argument(default, "ftp-remote-path")]
+ [EnvironmentVariable("FTP_REMOTE_PATH")]
+ [Description("remote path for FTP uploads")]
+ public string RemotePath { get; private set; } = "/";
+
+ /// <summary>
+ /// Gets a value indicating whether existing files should be overwritten.
+ /// </summary>
+ [Argument(default, "ftp-overwrite-existing")]
+ [EnvironmentVariable("FTP_OVERWRITE_EXISTING")]
+ [Description("overwrite existing files when uploading to FTP")]
+ public bool OverwriteExisting { get; private set; } = true;
+
+ /// <summary>
+ /// Gets the connection timeout value, in milliseconds.
+ /// </summary>
+ [Argument(default, "ftp-connection-timeout")]
+ [EnvironmentVariable("FTP_CONNECTION_TIMEOUT")]
+ [Description("FTP connection timeout, in milliseconds")]
+ [Range(0, int.MaxValue)]
+ public int ConnectionTimeout { get; private set; } = 5000;
+
+ /// <summary>
+ /// Gets the number of times failing uploads will be retried.
+ /// </summary>
+ [Argument(default, "ftp-retry-attempts")]
+ [EnvironmentVariable("FTP_RETRY_ATTEMPTS")]
+ [Description("number of times failing FTP uploads will be retried")]
+ [Range(0, 5)]
+ public int RetryAttempts { get; private set; } = 3;
+
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ if (Enabled && string.IsNullOrWhiteSpace(Address))
+ {
+ results.Add(new ValidationResult($"The Enabled field is true, but no Address has been specified."));
+ }
+
+ return results;
+ }
+ }
+ }
}
} \ No newline at end of file