2020-08-05 00:34:09 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-02-06 16:43:11 +00:00
|
|
|
|
using System.Net;
|
2020-08-05 00:34:09 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2021-02-06 16:43:11 +00:00
|
|
|
|
using FluentFTP;
|
2020-08-05 00:34:09 +00:00
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Server.DTOs
|
2020-05-09 22:16:16 +00:00
|
|
|
|
{
|
2020-08-05 00:34:09 +00:00
|
|
|
|
public enum StorageSpace
|
|
|
|
|
{
|
|
|
|
|
AuthoredFiles,
|
|
|
|
|
Patches,
|
|
|
|
|
Mirrors
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 22:16:16 +00:00
|
|
|
|
public class BunnyCdnFtpInfo
|
|
|
|
|
{
|
|
|
|
|
public string Username { get; set; }
|
|
|
|
|
public string Password { get; set; }
|
|
|
|
|
public string Hostname { get; set; }
|
2020-08-05 00:34:09 +00:00
|
|
|
|
|
|
|
|
|
public static async Task<BunnyCdnFtpInfo> GetCreds(StorageSpace space)
|
|
|
|
|
{
|
|
|
|
|
return (await Utils.FromEncryptedJson<Dictionary<string, BunnyCdnFtpInfo>>("bunnycdn"))[space.ToString()];
|
|
|
|
|
}
|
2021-02-06 16:43:11 +00:00
|
|
|
|
|
|
|
|
|
public async Task<FtpClient> GetClient()
|
|
|
|
|
{
|
2021-03-11 04:31:49 +00:00
|
|
|
|
return await CircuitBreaker.WithAutoRetryAllAsync(async () =>
|
|
|
|
|
{
|
|
|
|
|
var ftpClient = new FtpClient(Hostname, new NetworkCredential(Username, Password));
|
|
|
|
|
await ftpClient.ConnectAsync();
|
|
|
|
|
return ftpClient;
|
|
|
|
|
});
|
2021-02-06 16:43:11 +00:00
|
|
|
|
}
|
2020-05-09 22:16:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|