44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
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
|
|
});
|
|
}
|
|
}
|