add mirror list upload tasks
This commit is contained in:
parent
b28850f8b5
commit
52ef069f7b
@ -9,6 +9,8 @@ namespace EftPatchHelper.Interfaces
|
||||
public interface IFileUpload
|
||||
{
|
||||
public string DisplayName { get; set; }
|
||||
public string ServiceName { get; set; }
|
||||
public string HubEntryText { get; set; }
|
||||
public string GetLink();
|
||||
public Task<bool> UploadAsync(IProgress<double>? progress = null);
|
||||
}
|
||||
|
@ -10,17 +10,21 @@ namespace EftPatchHelper.Model
|
||||
private GoFileFile _uploadedFile;
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
public string ServiceName { get; set; }
|
||||
public string HubEntryText { get; set; }
|
||||
|
||||
public GoFileUpload(FileInfo file, string apiToken)
|
||||
{
|
||||
GoFile.ApiToken = apiToken;
|
||||
_file = file;
|
||||
DisplayName = $"GoFile Upload: {_file.Name}";
|
||||
ServiceName = "GoFile";
|
||||
DisplayName = $"{ServiceName} Upload: {_file.Name}";
|
||||
HubEntryText = $"Download from {ServiceName}";
|
||||
}
|
||||
|
||||
public string GetLink()
|
||||
{
|
||||
return _uploadedFile.Link;
|
||||
return _uploadedFile.DirectLink;
|
||||
}
|
||||
|
||||
public async Task<bool> UploadAsync(IProgress<double>? progress = null)
|
||||
|
@ -15,6 +15,8 @@ namespace EftPatchHelper.Model
|
||||
private INode _uploadedFile;
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
public string ServiceName { get; set; }
|
||||
public string HubEntryText { get; set; }
|
||||
|
||||
public MegaUpload(FileInfo file, string email, string password, string mfaKey = null)
|
||||
{
|
||||
@ -22,7 +24,9 @@ namespace EftPatchHelper.Model
|
||||
_file = file;
|
||||
_email = email;
|
||||
_password = password;
|
||||
DisplayName = $"Mega Upload: {_file.Name}";
|
||||
ServiceName = "Mega";
|
||||
DisplayName = $"{ServiceName} Upload: {_file.Name}";
|
||||
HubEntryText = $"Download from {ServiceName}";
|
||||
}
|
||||
|
||||
private async Task<bool> CheckLoginStatus()
|
||||
|
@ -38,5 +38,10 @@ namespace EftPatchHelper.Model
|
||||
/// Whether or not to upload the pather to mega.io
|
||||
/// </summary>
|
||||
public bool UploadToMega = false;
|
||||
|
||||
/// <summary>
|
||||
/// List of mirrors to upload to Gitea
|
||||
/// </summary>
|
||||
public Dictionary<string, string> MirrorList = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ namespace EftPatchHelper
|
||||
IFileProcessingTasks fileProcessingTasks,
|
||||
IPatchGenTasks patchGenTasks,
|
||||
IPatchTestingTasks patchTestingTasks,
|
||||
IReleaseCreator createReleaseTasks,
|
||||
IUploadTasks uploadTasks
|
||||
IUploadTasks uploadTasks,
|
||||
IReleaseCreator createReleaseTasks
|
||||
)
|
||||
{
|
||||
_settingsTasks = settingsTasks;
|
||||
@ -59,8 +59,8 @@ namespace EftPatchHelper
|
||||
_fileProcessingTasks.Run();
|
||||
_patchGenTasks.Run();
|
||||
_patchTestingTasks.Run();
|
||||
_createReleaseTasks.Run();
|
||||
_uploadTasks.Run();
|
||||
_createReleaseTasks.Run();
|
||||
}
|
||||
|
||||
private static IHost ConfigureHost(string[] args)
|
||||
|
@ -5,6 +5,7 @@ using Gitea.Model;
|
||||
using Gitea.Client;
|
||||
using Spectre.Console;
|
||||
using EftPatchHelper.Extensions;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace EftPatchHelper.Tasks
|
||||
{
|
||||
@ -81,6 +82,19 @@ namespace EftPatchHelper.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
public bool CreateMirrorList(FileInfo mirrorListFileInfo)
|
||||
{
|
||||
List<string> mirrors = _options.MirrorList.Values.ToList();
|
||||
|
||||
string json = JsonSerializer.Serialize(mirrors, new JsonSerializerOptions() { WriteIndented = true });
|
||||
|
||||
File.WriteAllText(mirrorListFileInfo.FullName, json);
|
||||
|
||||
mirrorListFileInfo.Refresh();
|
||||
|
||||
return mirrorListFileInfo.Exists;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
@ -93,9 +107,11 @@ namespace EftPatchHelper.Tasks
|
||||
|
||||
var repo = new RepositoryApi(Configuration.Default);
|
||||
|
||||
var release = MakeRelease(repo).ValidateOrExit<Release>();
|
||||
var fileInfo = new FileInfo(Path.Join(Environment.CurrentDirectory, "mirrors.json"));
|
||||
|
||||
var fileInfo = new FileInfo(_options.OutputPatchPath + ".zip");
|
||||
CreateMirrorList(fileInfo);
|
||||
|
||||
var release = MakeRelease(repo).ValidateOrExit<Release>();
|
||||
|
||||
UploadAsset(fileInfo, release, repo);
|
||||
}
|
||||
|
@ -62,14 +62,9 @@ namespace EftPatchHelper.Tasks
|
||||
{
|
||||
_options.IgnoreExistingDirectories = new ConfirmationPrompt("Skip existing directories? (you will be prompted if no)").Show(AnsiConsole.Console);
|
||||
|
||||
if (!_settings.UsingGitea()) return;
|
||||
|
||||
_options.CreateRelease = new ConfirmationPrompt("Create a release on gitea?").Show(AnsiConsole.Console);
|
||||
|
||||
if(_options.CreateRelease)
|
||||
if (_settings.UsingGitea())
|
||||
{
|
||||
// only allow upload options if the release is not being made
|
||||
return;
|
||||
_options.CreateRelease = new ConfirmationPrompt("Create a release on gitea?").Show(AnsiConsole.Console);
|
||||
}
|
||||
|
||||
if (_settings.UsingMega())
|
||||
|
@ -24,6 +24,12 @@ namespace EftPatchHelper.Tasks
|
||||
|
||||
if (!patcherFile.Exists) return false;
|
||||
|
||||
if(_settings.UsingGoFile() && _options.UploadToGoFile)
|
||||
{
|
||||
var gofile = new GoFileUpload(patcherFile, _settings.GoFileApiKey);
|
||||
_fileUploads.Add(gofile);
|
||||
}
|
||||
|
||||
if (_settings.UsingMega() && _options.UploadToMega)
|
||||
{
|
||||
var mega = new MegaUpload(patcherFile, _settings.MegaEmail, _settings.MegaPassword);
|
||||
@ -31,45 +37,17 @@ namespace EftPatchHelper.Tasks
|
||||
_fileUploads.Add(mega);
|
||||
}
|
||||
|
||||
if(_settings.UsingGoFile() && _options.UploadToGoFile)
|
||||
{
|
||||
var gofile = new GoFileUpload(patcherFile, _settings.GoFileApiKey);
|
||||
_fileUploads.Add(gofile);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CreateHubEntrySource()
|
||||
{
|
||||
var goFile = _fileUploads.SingleOrDefault(x => x.GetType() == typeof(GoFileUpload));
|
||||
var mega = _fileUploads.SingleOrDefault(x => x.GetType() == typeof(MegaUpload));
|
||||
|
||||
if(goFile == null || mega == null)
|
||||
{
|
||||
AnsiConsole.WriteLine("Failed to get required info to create hub entry source");
|
||||
return;
|
||||
}
|
||||
|
||||
var goFileLink = goFile.GetLink();
|
||||
var megaLink = mega.GetLink();
|
||||
|
||||
if(goFileLink == null || megaLink == null)
|
||||
{
|
||||
AnsiConsole.WriteLine("Failed to get link for uploaded files");
|
||||
return;
|
||||
}
|
||||
|
||||
string output = $"<p>Downgrade EFT Client files from version {_options.SourceClient.Version} to {_options.TargetClient.Version}</p>\n<p><br></p>";
|
||||
|
||||
if(_options.UploadToGoFile)
|
||||
foreach (var pair in _options.MirrorList)
|
||||
{
|
||||
output += $"\n<p><a href=\"{goFileLink}\">Download From GoFile</a></p>";
|
||||
}
|
||||
|
||||
if(_options.UploadToMega)
|
||||
{
|
||||
output += $"\n<p><a href=\"{megaLink}\">Download From Mega</a></p>";
|
||||
// value is the link, key is the hub entry text
|
||||
output += $"\n<p><a href=\"{pair.Value}\">{pair.Key}</a></p>";
|
||||
}
|
||||
|
||||
AnsiConsole.WriteLine(output);
|
||||
@ -124,6 +102,10 @@ namespace EftPatchHelper.Tasks
|
||||
AnsiConsole.MarkupLine($"[red]{pair.Key.DisplayName.EscapeMarkup()} failed[/]");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_options.MirrorList.Add(pair.Key.HubEntryText, pair.Key.GetLink());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -134,10 +116,9 @@ namespace EftPatchHelper.Tasks
|
||||
|
||||
public void Run()
|
||||
{
|
||||
if (!_options.CreateRelease)
|
||||
{
|
||||
UploadAllFiles().GetAwaiter().GetResult().ValidateOrExit();
|
||||
}
|
||||
if (!_options.UploadToGoFile && !_options.UploadToMega) return;
|
||||
|
||||
UploadAllFiles().GetAwaiter().GetResult().ValidateOrExit();
|
||||
|
||||
CreateHubEntrySource();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user