This commit is contained in:
2026-03-30 11:07:30 +08:00
parent 2c44b3a4b2
commit d4a8e71733
74 changed files with 1751 additions and 421 deletions

View 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
});
}
}