add file hash to mirror list
This commit is contained in:
parent
acbebe3821
commit
2ebc596321
@ -11,6 +11,7 @@ namespace EftPatchHelper.Interfaces
|
||||
public string DisplayName { get; set; }
|
||||
public string ServiceName { get; set; }
|
||||
public string HubEntryText { get; set; }
|
||||
public FileInfo UploadFileInfo { get; }
|
||||
public string GetLink();
|
||||
public Task<bool> UploadAsync(IProgress<double>? progress = null);
|
||||
}
|
||||
|
8
EftPatchHelper/EftPatchHelper/Model/DownloadMirror.cs
Normal file
8
EftPatchHelper/EftPatchHelper/Model/DownloadMirror.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace EftPatchHelper.Model
|
||||
{
|
||||
public class DownloadMirror
|
||||
{
|
||||
public string Link { get; set; }
|
||||
public string Hash { get; set; }
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace EftPatchHelper.Model
|
||||
{
|
||||
public class GoFileUpload : IFileUpload
|
||||
{
|
||||
private FileInfo _file;
|
||||
public FileInfo UploadFileInfo { get; private set; }
|
||||
private GoFileFile _uploadedFile;
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
@ -16,9 +16,9 @@ namespace EftPatchHelper.Model
|
||||
public GoFileUpload(FileInfo file, string apiToken)
|
||||
{
|
||||
GoFile.ApiToken = apiToken;
|
||||
_file = file;
|
||||
UploadFileInfo = file;
|
||||
ServiceName = "GoFile";
|
||||
DisplayName = $"{ServiceName} Upload: {_file.Name}";
|
||||
DisplayName = $"{ServiceName} Upload: {UploadFileInfo.Name}";
|
||||
HubEntryText = $"Download from {ServiceName}";
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ namespace EftPatchHelper.Model
|
||||
|
||||
public async Task<bool> UploadAsync(IProgress<double>? progress = null)
|
||||
{
|
||||
var uploadedFile = await GoFile.UploadFileAsync(_file, progress);
|
||||
var uploadedFile = await GoFile.UploadFileAsync(UploadFileInfo, progress);
|
||||
|
||||
if(uploadedFile == null) return false;
|
||||
|
||||
|
@ -6,7 +6,7 @@ namespace EftPatchHelper.Model
|
||||
{
|
||||
public class MegaUpload : IFileUpload, IDisposable
|
||||
{
|
||||
private FileInfo _file;
|
||||
public FileInfo UploadFileInfo { get; private set; }
|
||||
private MegaApiClient _client;
|
||||
private string _email;
|
||||
private string _password;
|
||||
@ -21,11 +21,11 @@ namespace EftPatchHelper.Model
|
||||
public MegaUpload(FileInfo file, string email, string password, string mfaKey = null)
|
||||
{
|
||||
_client = new MegaApiClient();
|
||||
_file = file;
|
||||
UploadFileInfo = file;
|
||||
_email = email;
|
||||
_password = password;
|
||||
ServiceName = "Mega";
|
||||
DisplayName = $"{ServiceName} Upload: {_file.Name}";
|
||||
DisplayName = $"{ServiceName} Upload: {UploadFileInfo.Name}";
|
||||
HubEntryText = $"Download from {ServiceName}";
|
||||
}
|
||||
|
||||
@ -76,18 +76,18 @@ namespace EftPatchHelper.Model
|
||||
|
||||
public async Task<bool> UploadAsync(IProgress<double>? progress = null)
|
||||
{
|
||||
_file.Refresh();
|
||||
UploadFileInfo.Refresh();
|
||||
|
||||
if (!_file.Exists) return false;
|
||||
if (!UploadFileInfo.Exists) return false;
|
||||
|
||||
if(!await CheckLoginStatus())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using var fileStream = _file.OpenRead();
|
||||
using var fileStream = UploadFileInfo.OpenRead();
|
||||
|
||||
_uploadedFile = await _client.UploadAsync(fileStream, _file.Name, _uploadFolder, progress);
|
||||
_uploadedFile = await _client.UploadAsync(fileStream, UploadFileInfo.Name, _uploadFolder, progress);
|
||||
|
||||
return _uploadedFile != null;
|
||||
}
|
||||
|
@ -42,6 +42,6 @@ namespace EftPatchHelper.Model
|
||||
/// <summary>
|
||||
/// List of mirrors to upload to Gitea
|
||||
/// </summary>
|
||||
public Dictionary<string, string> MirrorList = new Dictionary<string, string>();
|
||||
public Dictionary<string, DownloadMirror> MirrorList = new Dictionary<string, DownloadMirror>();
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ namespace EftPatchHelper.Tasks
|
||||
|
||||
public bool CreateMirrorList(FileInfo mirrorListFileInfo)
|
||||
{
|
||||
List<string> mirrors = _options.MirrorList.Values.ToList();
|
||||
List<DownloadMirror> mirrors = _options.MirrorList.Values.ToList();
|
||||
|
||||
string json = JsonSerializer.Serialize(mirrors, new JsonSerializerOptions() { WriteIndented = true });
|
||||
|
||||
@ -99,6 +99,10 @@ namespace EftPatchHelper.Tasks
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var fileInfo = new FileInfo(Path.Join(Environment.CurrentDirectory, "mirrors.json"));
|
||||
|
||||
CreateMirrorList(fileInfo);
|
||||
|
||||
if (!_options.CreateRelease) return;
|
||||
|
||||
Configuration.Default.BasePath = _settings.GiteaApiBasePath;
|
||||
@ -107,10 +111,6 @@ namespace EftPatchHelper.Tasks
|
||||
|
||||
var repo = new RepositoryApi(Configuration.Default);
|
||||
|
||||
var fileInfo = new FileInfo(Path.Join(Environment.CurrentDirectory, "mirrors.json"));
|
||||
|
||||
CreateMirrorList(fileInfo);
|
||||
|
||||
var release = MakeRelease(repo).ValidateOrExit<Release>();
|
||||
|
||||
UploadAsset(fileInfo, release, repo);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using EftPatchHelper.Interfaces;
|
||||
using EftPatchHelper.Model;
|
||||
using Spectre.Console;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace EftPatchHelper.Tasks
|
||||
{
|
||||
@ -18,6 +19,17 @@ namespace EftPatchHelper.Tasks
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
private static string GetFileHash(FileInfo file)
|
||||
{
|
||||
using (MD5 md5Service = MD5.Create())
|
||||
using (var sourceStream = file.OpenRead())
|
||||
{
|
||||
byte[] sourceHash = md5Service.ComputeHash(sourceStream);
|
||||
|
||||
return Convert.ToBase64String(sourceHash);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> BuildUploadList()
|
||||
{
|
||||
var patcherFile = new FileInfo(_options.OutputPatchPath + ".zip");
|
||||
@ -47,7 +59,7 @@ namespace EftPatchHelper.Tasks
|
||||
foreach (var pair in _options.MirrorList)
|
||||
{
|
||||
var displayText = pair.Key;
|
||||
var link = pair.Value;
|
||||
var link = pair.Value.Link;
|
||||
|
||||
if(link.Contains("gofile.io/download/direct/"))
|
||||
{
|
||||
@ -112,7 +124,13 @@ namespace EftPatchHelper.Tasks
|
||||
}
|
||||
else
|
||||
{
|
||||
_options.MirrorList.Add(pair.Key.HubEntryText, pair.Key.GetLink());
|
||||
DownloadMirror mirror = new DownloadMirror()
|
||||
{
|
||||
Link = pair.Key.GetLink(),
|
||||
Hash = GetFileHash(pair.Key.UploadFileInfo)
|
||||
};
|
||||
|
||||
_options.MirrorList.Add(pair.Key.HubEntryText, mirror);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user