This commit is contained in:
dingo
2025-12-25 19:01:20 -05:00
parent 24cf771d80
commit 3d34235196
2 changed files with 40 additions and 32 deletions
+7 -8
View File
@@ -33,14 +33,13 @@
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
<h3 class="text-xl font-semibold text-white mb-2">MinIO Not Configured</h3>
<p class="text-gray-400 mb-4">To browse CDN files, configure MinIO credentials in appsettings.json:</p>
<pre class="bg-gray-900 p-4 rounded text-left text-sm text-gray-300 max-w-md mx-auto">"MinIO": {
"Endpoint": "assets.aeternalisgames.com",
"AccessKey": "your-access-key",
"SecretKey": "your-secret-key",
"BucketName": "downloads",
"UseSSL": true
}</pre>
<p class="text-gray-400 mb-4">To browse CDN files, set these environment variables (Kubernetes secret):</p>
<pre class="bg-gray-900 p-4 rounded text-left text-sm text-gray-300 max-w-md mx-auto">MINIO_ENDPOINT=assets.aeternalisgames.com
MINIO_ACCESS_KEY=your-access-key
MINIO_SECRET_KEY=your-secret-key
MINIO_BUCKET=downloads
MINIO_USE_SSL=true</pre>
<p class="text-gray-500 text-sm mt-4">Or configure in appsettings.json under "MinIO" section.</p>
</div>
}
else
+33 -24
View File
@@ -10,7 +10,6 @@ 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
@@ -32,46 +31,56 @@ public interface ICdnBrowserService
public class MinioCdnBrowserService : ICdnBrowserService
{
private readonly IMinioClient? _client;
private readonly MinioConfig _config;
private readonly string _bucketName;
private readonly ILogger<MinioCdnBrowserService> _logger;
private readonly bool _isConfigured;
public bool IsConfigured => _client != null;
public bool IsConfigured => _isConfigured;
public MinioCdnBrowserService(IConfiguration configuration, ILogger<MinioCdnBrowserService> logger)
{
_logger = logger;
_config = configuration.GetSection("MinIO").Get<MinioConfig>() ?? new MinioConfig();
// 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 environment variables first (for Kubernetes secrets), fall back to appsettings
var endpoint = Environment.GetEnvironmentVariable("MINIO_ENDPOINT")
?? configuration["MinIO:Endpoint"]
?? "";
var accessKey = Environment.GetEnvironmentVariable("MINIO_ACCESS_KEY")
?? configuration["MinIO:AccessKey"]
?? "";
var secretKey = Environment.GetEnvironmentVariable("MINIO_SECRET_KEY")
?? configuration["MinIO:SecretKey"]
?? "";
_bucketName = Environment.GetEnvironmentVariable("MINIO_BUCKET")
?? configuration["MinIO:BucketName"]
?? "downloads";
var useSSL = Environment.GetEnvironmentVariable("MINIO_USE_SSL")?.ToLower() != "false"
&& (configuration.GetValue<bool?>("MinIO:UseSSL") ?? true);
var hasCredentials = !string.IsNullOrEmpty(accessKey) && !string.IsNullOrEmpty(secretKey);
_isConfigured = hasCredentials && !string.IsNullOrEmpty(endpoint);
if (_isConfigured)
{
try
{
var builder = new MinioClient()
.WithEndpoint(_config.Endpoint)
.WithSSL(_config.UseSSL);
if (hasCredentials)
{
builder = builder.WithCredentials(_config.AccessKey, _config.SecretKey);
}
// For anonymous access, we don't set credentials
_client = new MinioClient()
.WithEndpoint(endpoint)
.WithCredentials(accessKey, secretKey)
.WithSSL(useSSL)
.Build();
_client = builder.Build();
_logger.LogInformation("MinIO client initialized for endpoint: {Endpoint} (Anonymous: {Anon})",
_config.Endpoint, _config.AnonymousAccess && !hasCredentials);
_logger.LogInformation("MinIO client initialized for endpoint: {Endpoint}, bucket: {Bucket}", endpoint, _bucketName);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to initialize MinIO client");
_isConfigured = false;
}
}
else
{
_logger.LogWarning("MinIO not configured - CDN browsing disabled. Set MinIO:AccessKey/SecretKey or MinIO:AnonymousAccess=true");
_logger.LogWarning("MinIO not configured - CDN browsing disabled. Set MINIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY environment variables or MinIO section in appsettings.");
}
}
@@ -92,7 +101,7 @@ public class MinioCdnBrowserService : ICdnBrowserService
prefix += "/";
var listArgs = new ListObjectsArgs()
.WithBucket(_config.BucketName)
.WithBucket(_bucketName)
.WithPrefix(prefix)
.WithRecursive(false); // Only list current level
@@ -135,7 +144,7 @@ public class MinioCdnBrowserService : ICdnBrowserService
prefix += "/";
var listArgs = new ListObjectsArgs()
.WithBucket(_config.BucketName)
.WithBucket(_bucketName)
.WithPrefix(prefix)
.WithRecursive(false);