Compare commits

...
4 Commits
Author SHA1 Message Date
xrain 62ddd6698e now simapiauth can use , for role 2022-09-02 09:47:41 +08:00
xrain b2a6e5f40f make storage bucket public 2022-08-17 20:26:25 +08:00
xrain 801f698dcf add storage get url 2022-08-17 19:37:39 +08:00
xrain 9c939426ba fix logger 2022-08-05 02:33:47 +08:00
3 changed files with 39 additions and 30 deletions
+9 -3
View File
@@ -19,13 +19,16 @@ namespace SimApi.Attributes
//默认是user登录类型 //默认是user登录类型
public SimApiAuthAttribute() public SimApiAuthAttribute()
{ {
Types = new[] { "user" }; Types = new[]
{
"user"
};
} }
//只检测一种用户类型的快捷方式 //只检测一种用户类型的快捷方式
public SimApiAuthAttribute(string type) public SimApiAuthAttribute(string type)
{ {
Types = new[] { type }; Types = type.Split(",");
} }
//设定特定类型的检测 //设定特定类型的检测
@@ -37,7 +40,10 @@ namespace SimApi.Attributes
//只检测一种用户类型的快捷方式 //只检测一种用户类型的快捷方式
public SimApiAuthAttribute(string type, string url) public SimApiAuthAttribute(string type, string url)
{ {
Types = new[] { type }; Types = new[]
{
type
};
new HttpPostAttribute(url); new HttpPostAttribute(url);
} }
+21 -18
View File
@@ -15,7 +15,7 @@ namespace SimApi.Helpers
private string ServeUrl { get; } private string ServeUrl { get; }
private string Bucket { get; } public string Bucket { get; }
private IHttpContextAccessor HttpContextAccessor { get; } private IHttpContextAccessor HttpContextAccessor { get; }
@@ -49,41 +49,44 @@ namespace SimApi.Helpers
} }
Mc = mcb.Build(); Mc = mcb.Build();
bool found = Mc.BucketExistsAsync(new BucketExistsArgs().WithBucket(Bucket)).Result; var found = Mc.BucketExistsAsync(new BucketExistsArgs().WithBucket(Bucket)).Result;
if (!found) if (!found)
{ {
Mc.MakeBucketAsync(new MakeBucketArgs().WithBucket(Bucket)).Wait(); Mc.MakeBucketAsync(new MakeBucketArgs().WithBucket(Bucket)).Wait();
} }
} }
/// <summary>
/// 获取上传的URL
/// </summary>
/// <param name="path"></param>
/// <param name="expire"></param>
/// <returns></returns>
public string GetUploadUrl(string path, int expire = 7200) public string GetUploadUrl(string path, int expire = 7200)
{
try
{ {
return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket) return Mc.PresignedPutObjectAsync(new PresignedPutObjectArgs().WithBucket(Bucket)
.WithObject(path).WithExpiry(expire)).Result; .WithObject(path).WithExpiry(expire)).Result;
} }
catch (MinioException e)
/// <summary>
/// 获取下载的URL
/// </summary>
/// <param name="path"></param>
/// <param name="expire"></param>
/// <returns></returns>
public string GetDownloadUrl(string path, int expire = 600)
{ {
Console.WriteLine("Error occurred: " + e); return Mc.PresignedGetObjectAsync(new PresignedGetObjectArgs().WithBucket(Bucket).WithObject(path)
return e.Message; .WithExpiry(expire)).Result;
}
} }
public string UploadFile(string path, Stream stream, string contentType = "image/png") public string UploadFile(string path, Stream stream, string contentType = "image/png")
{ {
try Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).WithObjectSize(stream.Length)
{ .WithStreamData(stream).WithContentType(contentType)).Wait();
Mc.PutObjectAsync(new PutObjectArgs().WithBucket(Bucket).WithObject(path).
WithObjectSize(stream.Length).WithStreamData(stream).WithContentType(contentType)).Wait();
return null; return null;
} }
catch (MinioException e)
{
Console.WriteLine("Error occurred: " + e);
return e.Message;
}
}
public string FullUrl(string path) public string FullUrl(string path)
{ {
+1 -1
View File
@@ -198,7 +198,7 @@ namespace SimApi
{ {
var options = builder.ApplicationServices.GetRequiredService<SimApiOptions>(); var options = builder.ApplicationServices.GetRequiredService<SimApiOptions>();
var logger = builder.ApplicationServices.GetRequiredService<ILogger>(); var logger = builder.ApplicationServices.GetRequiredService<ILogger<SimApiOptions>>();
if (options.EnableForwardHeaders) if (options.EnableForwardHeaders)
{ {