[#60] Services: Encrypt zip files for backup and upload
Test / Run tests (push) Successful in 2m12s
Test / Run tests (push) Successful in 2m12s
This commit is contained in:
1 parent
f388ddbe41
commit
4bb13dbb06
10 files changed
+116
-73
No files matched your search
@@ -489,7 +489,7 @@ namespace Elwig.Helpers {
|
||||
.Replace("ß", "ss").Replace("ẞ", "SS");
|
||||
}
|
||||
|
||||
public static HttpClient GetHttpClient(string? username = null, string? password = null, string? accept = null) {
|
||||
public static HttpClient GetHttpClient(string? username = null, ReadOnlyMemory<char> password = default, string? accept = null) {
|
||||
var client = new HttpClient() {
|
||||
Timeout = TimeSpan.FromSeconds(5),
|
||||
};
|
||||
@@ -498,7 +498,7 @@ namespace Elwig.Helpers {
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
if (accept != null)
|
||||
client.DefaultRequestHeaders.Accept.Add(new(accept));
|
||||
if (username != null || password != null)
|
||||
if (username != null || !password.IsEmpty)
|
||||
client.DefaultRequestHeaders.Authorization = new("Basic", Convert.ToBase64String(Utils.UTF8.GetBytes($"{username}:{password}")));
|
||||
return client;
|
||||
}
|
||||
@@ -512,7 +512,7 @@ namespace Elwig.Helpers {
|
||||
return ((string)data["version"]!, (string)data["url"]!, (long)data["size"]!);
|
||||
}
|
||||
|
||||
public static async Task UploadExportData(string zip, string url, string username, string password) {
|
||||
public static async Task UploadExportData(string zip, string url, string username, ReadOnlyMemory<char> password) {
|
||||
if (url.StartsWith("https://elwig.at/clients/"))
|
||||
url = "https://sync.elwig.at/" + url[25..];
|
||||
if (!url.EndsWith('/')) url += "/";
|
||||
@@ -523,7 +523,7 @@ namespace Elwig.Helpers {
|
||||
res.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public static async Task<JsonArray> GetExportMetaData(string url, string username, string password) {
|
||||
public static async Task<JsonArray> GetExportMetaData(string url, string username, ReadOnlyMemory<char> password) {
|
||||
if (url.StartsWith("https://elwig.at/clients/"))
|
||||
url = "https://sync.elwig.at/" + url[25..];
|
||||
using var client = GetHttpClient(username, password, accept: "application/json");
|
||||
@@ -551,7 +551,7 @@ namespace Elwig.Helpers {
|
||||
var (host, port, mode, username, password, _, _) = App.Config.Smtp.Value;
|
||||
var client = new SmtpClient();
|
||||
await client.ConnectAsync(host, port, mode == "starttls" ? SecureSocketOptions.StartTls : SecureSocketOptions.None);
|
||||
await client.AuthenticateAsync(username, password);
|
||||
await client.AuthenticateAsync(username, password.ToString());
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user