diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-06-27 12:05:52 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-06-27 12:05:52 -0500 |
| commit | 5a663143c92215262f02aa40eae9b36b32c26ff2 (patch) | |
| tree | c2e33795d639d98b39e787d63984e2773f763fc5 /src | |
| parent | 7d3432f1e1b290cfafd007fea1372be968881301 (diff) | |
| download | slskd-5a663143c92215262f02aa40eae9b36b32c26ff2.tar.gz | |
stub FTPService
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Integrations/FTP/FTPService.cs | 61 | ||||
| -rw-r--r-- | src/slskd/Integrations/FTP/IFTPService.cs | 26 | ||||
| -rw-r--r-- | src/slskd/Startup.cs | 2 |
3 files changed, 89 insertions, 0 deletions
diff --git a/src/slskd/Integrations/FTP/FTPService.cs b/src/slskd/Integrations/FTP/FTPService.cs new file mode 100644 index 00000000..b704063c --- /dev/null +++ b/src/slskd/Integrations/FTP/FTPService.cs @@ -0,0 +1,61 @@ +// <copyright file="FTPService.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd.Integrations.FTP +{ + using System; + using System.Threading.Tasks; + using FluentFTP; + using Microsoft.Extensions.Logging; + using static slskd.Options.IntegrationOptions; + + public class FTPService : IFTPService + { + public FTPService( + Microsoft.Extensions.Options.IOptionsMonitor<Options> optionsMonitor, + ILogger<FTPService> log) + { + Options = optionsMonitor.CurrentValue; + Log = log; + + FtpEncryptionMode encryptionMode; + + try + { + encryptionMode = (FtpEncryptionMode)Enum.Parse(typeof(FtpEncryptionMode), FTPOptions.EncryptionMode, ignoreCase: true); + } + catch (Exception ex) + { + // Options should validate that the given string is parsable to FtpEncryptionMode through EnumAttribute; if this throws there's a bug somewhere. + throw new ArgumentException($"Failed to parse {typeof(FtpEncryptionMode).Name} from application Options. This is most likely a programming error; please file a GitHub issue and include your FTP configuration.", ex); + } + + Client = new FtpClient(FTPOptions.Address, FTPOptions.Port, FTPOptions.Username, FTPOptions.Password); + Client.EncryptionMode = encryptionMode; + } + + private Options Options { get; } + private FTPOptions FTPOptions => Options.Integration.FTP; + private ILogger<FTPService> Log { get; set; } + private FtpClient Client { get; set; } + + public Task UploadAsync(string filename) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/slskd/Integrations/FTP/IFTPService.cs b/src/slskd/Integrations/FTP/IFTPService.cs new file mode 100644 index 00000000..11c12073 --- /dev/null +++ b/src/slskd/Integrations/FTP/IFTPService.cs @@ -0,0 +1,26 @@ +// <copyright file="IFTPService.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd.Integrations.FTP +{ + using System.Threading.Tasks; + + public interface IFTPService + { + Task UploadAsync(string filename); + } +} diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index dd44fd87..ddf2f637 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -35,6 +35,7 @@ namespace slskd using Serilog; using slskd.Authentication; using slskd.Cryptography; + using slskd.Integrations.FTP; using slskd.Management; using slskd.Messaging; using slskd.Peer; @@ -186,6 +187,7 @@ namespace slskd services.AddSingleton<ISearchService, SearchService>(); services.AddSingleton<IPeerService, PeerService>(); services.AddSingleton<IManagementService, ManagementService>(); + services.AddSingleton<IFTPService, FTPService>(); services.AddHostedService<Service>(); services.AddSingleton(_ => Service.SoulseekClient); |
