QOL
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user