2024-08-20 10:14:15 +08:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-08-14 23:57:43 +08:00
|
|
|
|
using Minio;
|
|
|
|
|
|
|
|
|
|
namespace Bunny.Common.Connect;
|
|
|
|
|
|
|
|
|
|
public static class MinioContext
|
|
|
|
|
{
|
|
|
|
|
public static IMinioClient? MinioClient;
|
|
|
|
|
public static readonly string BucketName = AppSettings.GetConfig("Minio:BucketName");
|
|
|
|
|
|
|
|
|
|
public static void AddMinioContext(this WebApplicationBuilder builder)
|
2024-08-20 10:14:15 +08:00
|
|
|
|
{
|
|
|
|
|
Task.Run(Connect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Connect()
|
2024-08-14 23:57:43 +08:00
|
|
|
|
{
|
|
|
|
|
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-08-20 10:14:15 +08:00
|
|
|
|
Console.WriteLine($"Minio 已连接...\n初始化桶:{BucketName}");
|
2024-08-14 23:57:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|