From 1fa5e0c0372eea17302177a339c68b4a9a620ec2 Mon Sep 17 00:00:00 2001 From: Megghy Date: Wed, 26 Feb 2025 08:07:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0headerapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/PublicController.cs | 11 ++++++++--- Modules/PixivFavoriteDownloader.cs | 2 +- Program.cs | 7 +++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Controllers/PublicController.cs b/Controllers/PublicController.cs index c729b74..5a79cbd 100644 --- a/Controllers/PublicController.cs +++ b/Controllers/PublicController.cs @@ -6,10 +6,15 @@ namespace MegghysAPI.Controllers [ApiController] public class PublicController : MControllerBase { - [Route("header")] - public IActionResult Header() + [HttpGet("header")] + public IActionResult Header(bool? order = false) { - return Ok(string.Join(",", context.Request.Headers.Keys)); + var headers = Request.Headers.Select(h => $"{h.Key}: {h.Value}"); + if (order == true) + { + headers = headers.OrderBy(h => h); + } + return Ok(string.Join(Environment.NewLine, headers)); } } } diff --git a/Modules/PixivFavoriteDownloader.cs b/Modules/PixivFavoriteDownloader.cs index 353845b..1bb14e4 100644 --- a/Modules/PixivFavoriteDownloader.cs +++ b/Modules/PixivFavoriteDownloader.cs @@ -8,7 +8,7 @@ namespace MegghysAPI.Modules { public static class PixivFavoriteDownloader { - [AutoInit] + [AutoInit(Async = true)] public static void Init() { Favorites = DB.SQL.Select().ToList(); diff --git a/Program.cs b/Program.cs index fa1c672..532fbac 100644 --- a/Program.cs +++ b/Program.cs @@ -10,6 +10,7 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddFluentUIComponents(); +builder.Services.AddControllers(); var app = builder.Build(); @@ -29,9 +30,11 @@ app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); +app.UseRouting(); + +app.UseAntiforgery(); + app.MapControllers(); -app.MapBlazorHub(); -app.MapFallbackToPage("/_Host"); // 加载所有有 AutoInitAttribute 的类 // 获取当前Assembly