CDN Integration
This commit is contained in:
@@ -10,6 +10,7 @@ public class MinioConfig
|
||||
public string SecretKey { get; set; } = "";
|
||||
public string BucketName { get; set; } = "downloads";
|
||||
public bool UseSSL { get; set; } = true;
|
||||
public bool AnonymousAccess { get; set; } = false;
|
||||
}
|
||||
|
||||
public class CdnFile
|
||||
@@ -34,24 +35,34 @@ public class MinioCdnBrowserService : ICdnBrowserService
|
||||
private readonly MinioConfig _config;
|
||||
private readonly ILogger<MinioCdnBrowserService> _logger;
|
||||
|
||||
public bool IsConfigured => !string.IsNullOrEmpty(_config.AccessKey) && !string.IsNullOrEmpty(_config.SecretKey);
|
||||
public bool IsConfigured => _client != null;
|
||||
|
||||
public MinioCdnBrowserService(IConfiguration configuration, ILogger<MinioCdnBrowserService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = configuration.GetSection("MinIO").Get<MinioConfig>() ?? new MinioConfig();
|
||||
|
||||
if (IsConfigured)
|
||||
// Check if we have credentials OR anonymous access is enabled
|
||||
var hasCredentials = !string.IsNullOrEmpty(_config.AccessKey) && !string.IsNullOrEmpty(_config.SecretKey);
|
||||
|
||||
if (hasCredentials || _config.AnonymousAccess)
|
||||
{
|
||||
try
|
||||
{
|
||||
_client = new MinioClient()
|
||||
var builder = new MinioClient()
|
||||
.WithEndpoint(_config.Endpoint)
|
||||
.WithCredentials(_config.AccessKey, _config.SecretKey)
|
||||
.WithSSL(_config.UseSSL)
|
||||
.Build();
|
||||
.WithSSL(_config.UseSSL);
|
||||
|
||||
if (hasCredentials)
|
||||
{
|
||||
builder = builder.WithCredentials(_config.AccessKey, _config.SecretKey);
|
||||
}
|
||||
// For anonymous access, we don't set credentials
|
||||
|
||||
_logger.LogInformation("MinIO client initialized for endpoint: {Endpoint}", _config.Endpoint);
|
||||
_client = builder.Build();
|
||||
|
||||
_logger.LogInformation("MinIO client initialized for endpoint: {Endpoint} (Anonymous: {Anon})",
|
||||
_config.Endpoint, _config.AnonymousAccess && !hasCredentials);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -60,7 +71,7 @@ public class MinioCdnBrowserService : ICdnBrowserService
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("MinIO not configured - CDN browsing disabled. Set MinIO:AccessKey and MinIO:SecretKey in appsettings.");
|
||||
_logger.LogWarning("MinIO not configured - CDN browsing disabled. Set MinIO:AccessKey/SecretKey or MinIO:AnonymousAccess=true");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user