2024-09-02 23:20:28 +08:00
|
|
|
|
using log4net;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-08-14 23:57:43 +08:00
|
|
|
|
using Minio;
|
|
|
|
|
|
2024-09-02 21:28:21 +08:00
|
|
|
|
namespace Bunny.Common.Context.Middleware;
|
2024-08-14 23:57:43 +08:00
|
|
|
|
|
|
|
|
|
public static class MinioContext
|
|
|
|
|
{
|
2024-09-02 23:20:28 +08:00
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(MinioContext));
|
2024-08-14 23:57:43 +08:00
|
|
|
|
public static IMinioClient? MinioClient;
|
|
|
|
|
public static readonly string BucketName = AppSettings.GetConfig("Minio:BucketName");
|
|
|
|
|
|
|
|
|
|
public static void AddMinioContext(this WebApplicationBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
var endpoint = AppSettings.GetConfig("Minio:Url");
|
|
|
|
|
var accessKey = AppSettings.GetConfig("Minio:AccessKey");
|
|
|
|
|
var secretKey = AppSettings.GetConfig("Minio:SecretKey");
|
|
|
|
|
|
|
|
|
|
MinioClient = new MinioClient().WithEndpoint(endpoint).WithCredentials(accessKey, secretKey)
|
|
|
|
|
// .WithSSL() // 使用HTTPS
|
|
|
|
|
.Build();
|
2024-09-03 13:48:02 +08:00
|
|
|
|
Log.Info($"Minio 初始化...\t初始化桶:{BucketName}");
|
2024-08-14 23:57:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|