as is
This commit is contained in:
43
StopShopping.AdminApi/Routes/Common.cs
Normal file
43
StopShopping.AdminApi/Routes/Common.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Antiforgery;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using StopShopping.Services;
|
||||
using StopShopping.Services.Models.Req;
|
||||
using StopShopping.Services.Models.Resp;
|
||||
|
||||
namespace StopShopping.AdminApi.Routes;
|
||||
|
||||
public static class Common
|
||||
{
|
||||
public static RouteGroupBuilder MapCommon(this RouteGroupBuilder routes)
|
||||
{
|
||||
routes.MapPost("/common/upload", UploadAsync)
|
||||
.WithTags(OpenApiTags.通用.ToString());
|
||||
|
||||
|
||||
routes.MapPost("/common/antiforgery-token", AntiForgeryToken)
|
||||
.WithTags(OpenApiTags.通用.ToString());
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
private static async Task<ApiResponse<FileUploadResp>> UploadAsync(
|
||||
[FromForm] UploadParams payload,
|
||||
IFileService fileService,
|
||||
HttpContext httpContext)
|
||||
{
|
||||
return await fileService.UploadFileAsync(payload);
|
||||
}
|
||||
|
||||
private static ApiResponse<AntiForgeryToken> AntiForgeryToken(
|
||||
HttpContext httpContext,
|
||||
IAntiforgery antiforgery)
|
||||
{
|
||||
var antiforgeryToken = antiforgery.GetAndStoreTokens(httpContext);
|
||||
|
||||
return new ApiResponse<AntiForgeryToken>(new AntiForgeryToken
|
||||
{
|
||||
Token = antiforgeryToken.RequestToken,
|
||||
HeaderName = antiforgeryToken.HeaderName
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user