update minio

This commit is contained in:
2022-05-07 22:56:22 +08:00
parent 55ea40b757
commit 6fdb3da059
4 changed files with 35 additions and 17 deletions
+16 -12
View File
@@ -14,7 +14,9 @@ namespace SimApi.Helpers
public MinioClient Client => Mc; public MinioClient Client => Mc;
private string ServeUrl { get; } private string ServeUrl { get; }
private string Bucket { get; } private string Bucket { get; }
private IHttpContextAccessor HttpContextAccessor { get; } private IHttpContextAccessor HttpContextAccessor { get; }
public SimApiStorage(SimApiOptions apiOptions, IHttpContextAccessor httpContextAccessor) public SimApiStorage(SimApiOptions apiOptions, IHttpContextAccessor httpContextAccessor)
@@ -22,7 +24,7 @@ namespace SimApi.Helpers
var options = apiOptions.SimApiStorageOptions; var options = apiOptions.SimApiStorageOptions;
HttpContextAccessor = httpContextAccessor; HttpContextAccessor = httpContextAccessor;
var useSsl = false; var useSsl = false;
var endpoint = string.Empty; string endpoint;
if (options.Endpoint.StartsWith("http://")) if (options.Endpoint.StartsWith("http://"))
{ {
endpoint = options.Endpoint.Replace("http://", string.Empty); endpoint = options.Endpoint.Replace("http://", string.Empty);
@@ -39,19 +41,19 @@ namespace SimApi.Helpers
ServeUrl = options.ServeUrl; ServeUrl = options.ServeUrl;
Bucket = options.Bucket; Bucket = options.Bucket;
Console.WriteLine($"{endpoint} == {options.AccessKey} == {options.SecretKey}");
var mcb = new MinioClient().WithEndpoint(endpoint)
.WithCredentials(options.AccessKey, options.SecretKey);
if (useSsl) if (useSsl)
{ {
Mc = new MinioClient(endpoint, options.AccessKey, options.SecretKey).WithSSL(); mcb = mcb.WithSSL();
}
else
{
Mc = new MinioClient(endpoint, options.AccessKey, options.SecretKey);
} }
Mc = mcb.Build();
bool found = Mc.BucketExistsAsync(Bucket).Result; bool found = Mc.BucketExistsAsync(new BucketExistsArgs().WithBucket(Bucket)).Result;
if (!found) if (!found)
{ {
Mc.MakeBucketAsync(Bucket).Wait(); Mc.MakeBucketAsync(new MakeBucketArgs().WithBucket(Bucket)).Wait();
} }
} }
@@ -59,7 +61,8 @@ namespace SimApi.Helpers
{ {
try try
{ {
return Mc.PresignedPutObjectAsync(Bucket, path, expire).Result; return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket)
.WithObject(path).WithExpiry(expire)).Result;
} }
catch (MinioException e) catch (MinioException e)
{ {
@@ -72,7 +75,8 @@ namespace SimApi.Helpers
{ {
try try
{ {
Mc.PutObjectAsync(Bucket, path, stream, stream.Length).Wait(); Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).WithStreamData(stream))
.Wait();
return null; return null;
} }
catch (MinioException e) catch (MinioException e)
@@ -84,8 +88,8 @@ namespace SimApi.Helpers
public string FullUrl(string path) public string FullUrl(string path)
{ {
var httpRequest = HttpContextAccessor.HttpContext.Request; var httpRequest = HttpContextAccessor.HttpContext?.Request;
var url = $"{httpRequest.Scheme}://{httpRequest.Host}"; var url = $"{httpRequest?.Scheme}://{httpRequest?.Host}";
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
return path; return path;
+15
View File
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
namespace SimApi.Logger;
public class SimApiLoggerConfiguration
{
public int EventId { get; set; }
public Dictionary<LogLevel, ConsoleColor> LogLevels { get; set; } = new()
{
[LogLevel.Information] = ConsoleColor.Green
};
}
+1 -1
View File
@@ -4,7 +4,7 @@
"anonymousAuthentication": true "anonymousAuthentication": true
}, },
"profiles": { "profiles": {
"YYApi": { "SimApi": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"environmentVariables": { "environmentVariables": {
+3 -4
View File
@@ -17,7 +17,6 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'YYApi' " />
<ItemGroup> <ItemGroup>
<Folder Include="Helpers\" /> <Folder Include="Helpers\" />
<Folder Include="Communications\" /> <Folder Include="Communications\" />
@@ -28,9 +27,9 @@
<Folder Include="Configurations\" /> <Folder Include="Configurations\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Minio" Version="3.1.13" /> <PackageReference Include="Minio" Version="4.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.3.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.3.1" />
</ItemGroup> </ItemGroup>
<ProjectExtensions> <ProjectExtensions>
<MonoDevelop> <MonoDevelop>