[backend/razor] Improve public preview embeds (ISH-512)

Sensitive images are now not embedded. Image embeds now use the correct card type.
This commit is contained in:
Laura Hausmann 2024-10-05 20:36:56 +02:00
parent 6fe4b26019
commit cb28560dcf
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 5 additions and 2 deletions

View file

@ -21,4 +21,5 @@ public class PreviewAttachment
public required string Url; public required string Url;
public required string Name; public required string Name;
public required string? Alt; public required string? Alt;
public required bool Sensitive;
} }

View file

@ -61,11 +61,13 @@ else
<PageTitle>Note by @@@_note.User.Username - @_instanceName</PageTitle> <PageTitle>Note by @@@_note.User.Username - @_instanceName</PageTitle>
<HeadContent> <HeadContent>
@{ @{
var cardType = "summary";
var previewImageUrl = _note.User.AvatarUrl; var previewImageUrl = _note.User.AvatarUrl;
if (ShowMedia && _note.Attachments != null) if (ShowMedia && _note.Attachments != null)
{ {
if (_note.Attachments.FirstOrDefault(p => p.MimeType.StartsWith("image/")) is { } img) if (_note.Attachments.FirstOrDefault(p => p.MimeType.StartsWith("image/") && !p.Sensitive) is { } img)
{ {
cardType = "summary_large_image";
previewImageUrl = img.Url; previewImageUrl = img.Url;
} }
} }
@ -93,7 +95,7 @@ else
var title = _note.User.RawDisplayName is { } name ? $"{name} (@{username})" : $"@{username}"; var title = _note.User.RawDisplayName is { } name ? $"{name} (@{username})" : $"@{username}";
} }
<meta name="twitter:card" content="summary"> <meta name="twitter:card" content="@cardType">
<meta name="og:site_name" content="@_instanceName"> <meta name="og:site_name" content="@_instanceName">
<meta name="og:title" content="@title"> <meta name="og:title" content="@title">
<meta name="og:image" content="@previewImageUrl"> <meta name="og:image" content="@previewImageUrl">