using Microsoft.AspNetCore.Antiforgery; using Microsoft.AspNetCore.Mvc; using StopShopping.Services; using StopShopping.Services.Models.Req; using StopShopping.Services.Models.Resp; namespace StopShopping.Api.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> UploadAsync( [FromForm] UploadParams payload, IFileService fileService, HttpContext httpContext) { return await fileService.UploadFileAsync(payload); } private static ApiResponse AntiForgeryToken( HttpContext httpContext, IAntiforgery antiforgery) { var antiforgeryToken = antiforgery.GetAndStoreTokens(httpContext); return new ApiResponse(new AntiForgeryToken { Token = antiforgeryToken.RequestToken, HeaderName = antiforgeryToken.HeaderName }); } }