fix validation and upload, finish stuff

This commit is contained in:
IsWaffle 2024-03-21 20:48:49 -04:00
parent 4a10964f7f
commit 21d96d113a
8 changed files with 42 additions and 21 deletions

View File

@ -5,8 +5,8 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyVersion>1.5.1</AssemblyVersion> <AssemblyVersion>1.5.3</AssemblyVersion>
<FileVersion>1.5.1</FileVersion> <FileVersion>1.5.3</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -39,6 +39,11 @@ namespace EftPatchHelper.Model
/// </summary> /// </summary>
public bool UploadToMega = false; public bool UploadToMega = false;
/// <summary>
/// Whether or not to upload to all sftp site listing
/// </summary>
public bool UploadToSftpSites = false;
/// <summary> /// <summary>
/// List of mirrors to upload to Gitea /// List of mirrors to upload to Gitea
/// </summary> /// </summary>

View File

@ -22,6 +22,8 @@ public class SftpUpload : IFileUpload
_sessionOptions = new SessionOptions _sessionOptions = new SessionOptions
{ {
Protocol = Protocol.Sftp, Protocol = Protocol.Sftp,
UserName = _sftpInfo.Username,
Password = _sftpInfo.Password,
HostName = _sftpInfo.Hostname, HostName = _sftpInfo.Hostname,
PortNumber = _sftpInfo.Port, PortNumber = _sftpInfo.Port,
SshHostKeyFingerprint = _sftpInfo.HostKey SshHostKeyFingerprint = _sftpInfo.HostKey
@ -40,25 +42,23 @@ public class SftpUpload : IFileUpload
public Task<bool> UploadAsync(IProgress<double>? progress = null) public Task<bool> UploadAsync(IProgress<double>? progress = null)
{ {
TransferOptions transferOptions = new TransferOptions() TransferOptions transferOptions = new TransferOptions
{ {
TransferMode = TransferMode.Binary, TransferMode = TransferMode.Binary,
}; };
using Session session = new Session(); using Session session = new Session();
using var uploadStream = UploadFileInfo.OpenRead();
if (progress != null) if (progress != null)
{ {
session.FileTransferProgress += (_, args) => progress.Report(args.FileProgress); session.FileTransferProgress += (_, args) => progress.Report(Math.Floor(args.FileProgress * 100));
} }
try try
{ {
session.Open(_sessionOptions); session.Open(_sessionOptions);
session.PutFile(uploadStream, _sftpInfo.UploadPath, transferOptions); session.PutFiles(UploadFileInfo.FullName, $"{_sftpInfo.UploadPath}/{UploadFileInfo.Name}", false, transferOptions).Check();
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@ -25,24 +25,27 @@ public class SftpUploadInfo
[JsonPropertyName("httpPath")] [JsonPropertyName("httpPath")]
public string HttpPath { get; set; } = ""; public string HttpPath { get; set; } = "";
public bool Validate() public bool IsValid()
{ {
if (!string.IsNullOrWhiteSpace(Username)) if (string.IsNullOrWhiteSpace(Username))
return false; return false;
if (!string.IsNullOrWhiteSpace(Password)) if (string.IsNullOrWhiteSpace(Password))
return false; return false;
if (!string.IsNullOrWhiteSpace(HostKey)) if (string.IsNullOrWhiteSpace(Hostname))
return false;
if (string.IsNullOrWhiteSpace(HostKey))
return false; return false;
if (Port == 0) if (Port == 0)
return false; return false;
if (!string.IsNullOrWhiteSpace(UploadPath)) if (string.IsNullOrWhiteSpace(UploadPath))
return false; return false;
if (!string.IsNullOrWhiteSpace(HttpPath)) if (string.IsNullOrWhiteSpace(HttpPath))
return false; return false;
return true; return true;

View File

@ -80,6 +80,12 @@ namespace EftPatchHelper.Tasks
{ {
_options.UploadToGoFile = new ConfirmationPrompt("Upload to GoFile?").Show(AnsiConsole.Console); _options.UploadToGoFile = new ConfirmationPrompt("Upload to GoFile?").Show(AnsiConsole.Console);
} }
if (_settings.SftpUploads.Count > 0)
{
_options.UploadToSftpSites =
new ConfirmationPrompt($"Upload to SFTP sites? ( {_settings.SftpUploads.Count} sites )").Show(AnsiConsole.Console);
}
} }
public void Run() public void Run()

View File

@ -39,10 +39,13 @@ namespace EftPatchHelper.Tasks
return false; return false;
} }
AnsiConsole.WriteLine("Building mirrors list ...");
if(_settings.UsingGoFile() && _options.UploadToGoFile) if(_settings.UsingGoFile() && _options.UploadToGoFile)
{ {
var gofile = new GoFileUpload(patcherFile, _settings.GoFileApiKey, _settings.GoFileFolderId); var gofile = new GoFileUpload(patcherFile, _settings.GoFileApiKey, _settings.GoFileFolderId);
_fileUploads.Add(gofile); _fileUploads.Add(gofile);
AnsiConsole.WriteLine("Added MEGA");
} }
if (_settings.UsingMega() && _options.UploadToMega) if (_settings.UsingMega() && _options.UploadToMega)
@ -50,17 +53,22 @@ namespace EftPatchHelper.Tasks
var mega = new MegaUpload(patcherFile, _settings.MegaEmail, _settings.MegaPassword); var mega = new MegaUpload(patcherFile, _settings.MegaEmail, _settings.MegaPassword);
await mega.SetUploadFolder(_settings.MegaUploadFolder); await mega.SetUploadFolder(_settings.MegaUploadFolder);
_fileUploads.Add(mega); _fileUploads.Add(mega);
AnsiConsole.WriteLine("Added MEGA");
} }
if (_settings.SftpUploads.Count > 0 && _options.UploadToSftpSites)
{
foreach (var sftpInfo in _settings.SftpUploads) foreach (var sftpInfo in _settings.SftpUploads)
{ {
if (!sftpInfo.Validate()) if (!sftpInfo.IsValid())
{ {
continue; continue;
} }
AnsiConsole.WriteLine($"Added SFTP: {sftpInfo.Hostname}");
_fileUploads.Add(new SftpUpload(patcherFile, sftpInfo)); _fileUploads.Add(new SftpUpload(patcherFile, sftpInfo));
} }
}
return true; return true;
} }
@ -76,7 +84,6 @@ namespace EftPatchHelper.Tasks
continue; continue;
} }
var displayText = pair.Key; var displayText = pair.Key;
var link = pair.Value.Link; var link = pair.Value.Link;
@ -176,7 +183,7 @@ namespace EftPatchHelper.Tasks
public void Run() public void Run()
{ {
if (!_options.UploadToGoFile && !_options.UploadToMega) return; if (!_options.UploadToGoFile && !_options.UploadToMega && !_options.UploadToSftpSites) return;
UploadAllFiles().GetAwaiter().GetResult().ValidateOrExit(); UploadAllFiles().GetAwaiter().GetResult().ValidateOrExit();