refact: Fully refactor the conceptional structure and functional behaviour.

This commit is contained in:
2024-06-21 22:59:30 +08:00
parent 257f5d94ee
commit 2efe2fd5cd
64 changed files with 307 additions and 574 deletions

View File

@@ -1,13 +1,8 @@
using AngleSharp;
using AngleSharp.Dom;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using YaeBlog.Core.Abstractions;
using YaeBlog.Core.Builder;
using YaeBlog.Core.Extensions;
using YaeBlog.Core.Models;
namespace YaeBlog.Core.Processors;
@@ -45,31 +40,6 @@ public class ImagePostRenderProcessor(ILogger<ImagePostRenderProcessor> logger,
public string Name => "ImagePostRenderProcessor";
public static void AddImageApiEndpoint(BlogApplicationBuilder builder)
{
builder.ConfigureWebApplication((application) =>
{
application.MapGet("/api/files/{*filename}", ImageHandler);
});
}
private static Results<FileStreamHttpResult, NotFound> ImageHandler(string filename)
{
string contentType = "image/png";
if (filename.EndsWith("jpg") || filename.EndsWith("jpeg"))
{
contentType = "image/jpeg";
}
if (!Path.Exists(filename))
{
return TypedResults.NotFound();
}
Stream imageStream = File.OpenRead(filename);
return TypedResults.Stream(imageStream, contentType);
}
private string GenerateImageLink(string filename, string essayFilename)
{
if (!filename.Contains(essayFilename))
@@ -81,8 +51,8 @@ public class ImagePostRenderProcessor(ILogger<ImagePostRenderProcessor> logger,
if (!Path.Exists(filename))
{
logger.LogWarning("Failed to found image: {}.", filename);
return _options.BannerImage;
logger.LogError("Failed to found image: {}.", filename);
throw new InvalidOperationException();
}
string imageLink = "api/files/" + filename;