[backend/libmfm] Fix HTML markup being dropped for federation & public preview requests
This commit is contained in:
parent
3dabdc09e8
commit
7b61865287
2 changed files with 14 additions and 9 deletions
|
@ -1,24 +1,24 @@
|
|||
using Iceshrimp.Backend.Core.Configuration;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Extensions;
|
||||
using Iceshrimp.Backend.Core.Helpers.LibMfm.Conversion;
|
||||
using Iceshrimp.Parsing;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Iceshrimp.Backend.Components.PublicPreview.Renderers;
|
||||
|
||||
public class MfmRenderer(IOptions<Config.InstanceSection> config) : ISingletonService
|
||||
public class MfmRenderer(MfmConverter converter) : ISingletonService
|
||||
{
|
||||
private readonly MfmConverter _converter = new(config);
|
||||
|
||||
public async Task<MarkupString?> RenderAsync(
|
||||
string? text, string? host, List<Note.MentionedUser> mentions, List<Emoji> emoji, string rootElement
|
||||
)
|
||||
{
|
||||
if (text is null) return null;
|
||||
var parsed = Mfm.parse(text);
|
||||
var serialized = await _converter.ToHtmlAsync(parsed, mentions, host, emoji: emoji, rootElement: rootElement);
|
||||
|
||||
// Ensure we are rendering HTML markup (AsyncLocal)
|
||||
converter.SupportsHtmlFormatting.Value = true;
|
||||
|
||||
var serialized = await converter.ToHtmlAsync(parsed, mentions, host, emoji: emoji, rootElement: rootElement);
|
||||
return new MarkupString(serialized);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ using Iceshrimp.Backend.Core.Database;
|
|||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Extensions;
|
||||
using Iceshrimp.Backend.Core.Federation.Cryptography;
|
||||
using Iceshrimp.Backend.Core.Helpers.LibMfm.Conversion;
|
||||
using Iceshrimp.Backend.Core.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
@ -21,13 +22,17 @@ public class AuthorizedFetchMiddleware(
|
|||
SystemUserService systemUserSvc,
|
||||
ActivityPub.FederationControlService fedCtrlSvc,
|
||||
ILogger<AuthorizedFetchMiddleware> logger,
|
||||
IHostApplicationLifetime appLifetime
|
||||
IHostApplicationLifetime appLifetime,
|
||||
MfmConverter mfmConverter
|
||||
) : ConditionalMiddleware<AuthorizedFetchAttribute>, IMiddlewareService
|
||||
{
|
||||
public static ServiceLifetime Lifetime => ServiceLifetime.Scoped;
|
||||
|
||||
|
||||
public async Task InvokeAsync(HttpContext ctx, RequestDelegate next)
|
||||
{
|
||||
// Ensure we're rendering HTML markup (AsyncLocal)
|
||||
mfmConverter.SupportsHtmlFormatting.Value = true;
|
||||
|
||||
if (!config.Value.AuthorizedFetch)
|
||||
{
|
||||
await next(ctx);
|
||||
|
@ -147,4 +152,4 @@ public static partial class HttpContextExtensions
|
|||
ctx.Items.TryGetValue(ActorKey, out var actor);
|
||||
return actor as User;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue