This commit is contained in:
dingo
2025-12-26 23:11:59 -05:00
parent 9b757bf5ff
commit 4d26c37671
5 changed files with 294 additions and 26 deletions
+55
View File
@@ -25,6 +25,8 @@ public interface ICdnBrowserService
{
Task<List<CdnFile>> ListFilesAsync(string prefix, int maxKeys = 100, string? continuationToken = null);
Task<List<string>> ListPrefixesAsync(string prefix);
Task<bool> UploadFileAsync(string key, Stream stream, string contentType);
Task<bool> DeleteFileAsync(string key);
bool IsConfigured { get; }
}
@@ -163,4 +165,57 @@ public class MinioCdnBrowserService : ICdnBrowserService
return prefixes;
}
public async Task<bool> UploadFileAsync(string key, Stream stream, string contentType)
{
if (_client == null)
{
_logger.LogWarning("MinIO client not initialized");
return false;
}
try
{
var putArgs = new PutObjectArgs()
.WithBucket(_bucketName)
.WithObject(key)
.WithStreamData(stream)
.WithObjectSize(stream.Length)
.WithContentType(contentType);
await _client.PutObjectAsync(putArgs);
_logger.LogInformation("Uploaded file to MinIO: {Key}", key);
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error uploading file to MinIO: {Key}", key);
return false;
}
}
public async Task<bool> DeleteFileAsync(string key)
{
if (_client == null)
{
_logger.LogWarning("MinIO client not initialized");
return false;
}
try
{
var removeArgs = new RemoveObjectArgs()
.WithBucket(_bucketName)
.WithObject(key);
await _client.RemoveObjectAsync(removeArgs);
_logger.LogInformation("Deleted file from MinIO: {Key}", key);
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error deleting file from MinIO: {Key}", key);
return false;
}
}
}