:drunk: AI trying to fix bugs

This commit is contained in:
2025-07-06 21:15:30 +08:00
parent 3391c08c04
commit 7d1f096e87
70 changed files with 681 additions and 66945 deletions

View File

@ -35,24 +35,30 @@ namespace DysonNetwork.Common.Clients
return file;
}
public async Task<Stream> DownloadFileAsync(string fileId)
public async Task<Stream> GetFileStreamAsync(string fileId)
{
if (string.IsNullOrEmpty(fileId))
throw new ArgumentNullException(nameof(fileId));
var response = await _httpClient.GetAsync($"api/files/{fileId}/download");
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStreamAsync();
var stream = await response.Content.ReadAsStreamAsync();
if (stream == null)
throw new InvalidOperationException("Failed to read file stream from response.");
return stream;
}
public async Task<CloudFile> UploadFileAsync(Stream fileStream, string fileName, string contentType, string? folderId = null)
public async Task<CloudFile> UploadFileAsync(Stream fileStream, string fileName, string? contentType = null)
{
using var content = new MultipartFormDataContent();
var fileContent = new StreamContent(fileStream);
content.Add(fileContent, "file", fileName);
if (!string.IsNullOrEmpty(folderId))
if (!string.IsNullOrEmpty(contentType))
{
content.Add(new StringContent(folderId), "folderId");
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
}
content.Add(fileContent, "file", fileName);
var response = await _httpClient.PostAsync("api/files/upload", content);
response.EnsureSuccessStatusCode();
@ -61,6 +67,39 @@ namespace DysonNetwork.Common.Clients
var file = await JsonSerializer.DeserializeAsync<CloudFile>(responseStream, _jsonOptions);
return file;
}
public async Task<CloudFile> ProcessImageAsync(Stream imageStream, string fileName, string? contentType = null)
{
using var content = new MultipartFormDataContent();
var fileContent = new StreamContent(imageStream);
if (!string.IsNullOrEmpty(contentType))
{
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
}
content.Add(fileContent, "image", fileName);
var response = await _httpClient.PostAsync("api/files/process-image", content);
response.EnsureSuccessStatusCode();
await using var responseStream = await response.Content.ReadAsStreamAsync();
var file = await JsonSerializer.DeserializeAsync<CloudFile>(responseStream, _jsonOptions);
return file;
}
public async Task<string> GetFileUrl(string fileId, bool useCdn = false)
{
var url = $"api/files/{fileId}/url";
if (useCdn)
{
url += "?useCdn=true";
}
var response = await _httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
return result.Trim('"');
}
public async Task DeleteFileAsync(string fileId)
{