[CHANGE] Fixed auditing, storing images from account import

This commit is contained in:
max
2025-09-15 00:23:57 +02:00
parent e82736a45f
commit 0056a14f79
16 changed files with 201 additions and 47 deletions

View File

@@ -6,6 +6,7 @@ namespace Manager.YouTube;
public static class NetworkService
{
public const string Origin = "https://www.youtube.com";
private static readonly HttpClient HttpClient = new HttpClient();
public static async Task<Result<string>> MakeRequestAsync(HttpRequestMessage request, YouTubeClient client, bool skipAuthenticationHeader = false)
{
@@ -32,8 +33,25 @@ public static class NetworkService
}
}
public static async Task<Result<byte[]>> DownloadBytesAsync(HttpRequestMessage request, YouTubeClient client)
public static async Task<Result<DownloadResult>> DownloadBytesAsync(HttpRequestMessage request, YouTubeClient? client = null)
{
return ResultError.Fail("Not implemented");
try
{
var response = client != null ? await client.HttpClient.SendAsync(request) : await HttpClient.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
return ResultError.Fail($"Failed to get file to download, response code: {response.StatusCode}.");
}
var data = await response.Content.ReadAsByteArrayAsync();;
return new DownloadResult(data, response.Content.Headers.ContentType?.MediaType, response.Content.Headers.ContentDisposition?.FileName?.Trim('"'), response.Content.Headers.ContentLength ?? 0);
}
catch (Exception e)
{
return ResultError.Error(e);
}
}
}
}
public record DownloadResult(byte[] Data, string? ContentType, string? FileName, long ContentLength);