1
This commit is contained in:
33
Yes.Blog/Endpoints/Blogs/SearchEndpoint.cs
Normal file
33
Yes.Blog/Endpoints/Blogs/SearchEndpoint.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
namespace Yes.Blog.Endpoints.Blogs
|
||||
{
|
||||
public class SearchEndpoint : BlogEndpointScheme, IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder app) => app.MapPost("/search", Handle).DisableAntiforgery();
|
||||
|
||||
|
||||
public record Request(
|
||||
string S
|
||||
);
|
||||
private async Task<Microsoft.AspNetCore.Http.IResult> Handle(
|
||||
[FromForm] Request request,
|
||||
IOptionsMonitor<BlogSettings> options,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var settings = options.CurrentValue;
|
||||
if (string.IsNullOrEmpty(settings.ConnectionString) || string.IsNullOrEmpty(settings.DatabaseName) || string.IsNullOrEmpty(settings.DatabaseType))
|
||||
{
|
||||
return Results.Redirect("/Install/Index", false);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(request.S))
|
||||
{
|
||||
return Results.Redirect("/", false);
|
||||
}
|
||||
|
||||
var url = settings.SearchRoute.Replace(BlogRouteConst.Keyword.ToPlaceholder(), HttpUtility.UrlEncode(request.S));
|
||||
|
||||
return Results.Redirect(url, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user