Use proxy URL for generic image embeds

pull/1003/head
Tyrrrz 2 years ago
parent 6d3adf9fde
commit 8e5269f0ab

@ -23,6 +23,10 @@ public partial record Embed(
EmbedVideo? Video, EmbedVideo? Video,
EmbedFooter? Footer) EmbedFooter? Footer)
{ {
// Embeds can only have one image according to the API model,
// but the client can render multiple images in some cases.
public EmbedImage? Image => Images.FirstOrDefault();
public SpotifyTrackEmbedProjection? TryGetSpotifyTrack() => public SpotifyTrackEmbedProjection? TryGetSpotifyTrack() =>
SpotifyTrackEmbedProjection.TryResolve(this); SpotifyTrackEmbedProjection.TryResolve(this);

@ -150,11 +150,10 @@ internal class JsonMessageWriter : MessageWriter
await WriteEmbedImageAsync(embed.Thumbnail, cancellationToken); await WriteEmbedImageAsync(embed.Thumbnail, cancellationToken);
} }
// Legacy: backwards-compatibility for old embeds with a single image if (embed.Image is not null)
if (embed.Images.Count > 0)
{ {
_writer.WritePropertyName("image"); _writer.WritePropertyName("image");
await WriteEmbedImageAsync(embed.Images[0], cancellationToken); await WriteEmbedImageAsync(embed.Image, cancellationToken);
} }
if (embed.Footer is not null) if (embed.Footer is not null)

@ -392,11 +392,11 @@
</div> </div>
} }
// Generic image embed // Generic image embed
else if (embed.Kind == EmbedKind.Image && !string.IsNullOrWhiteSpace(embed.Url)) else if (embed.Kind == EmbedKind.Image && !string.IsNullOrWhiteSpace(embed.Image?.Url))
{ {
<div class="chatlog__embed"> <div class="chatlog__embed">
<a href="@await ResolveAssetUrlAsync(embed.Url)"> <a href="@await ResolveAssetUrlAsync(embed.Image.ProxyUrl ?? embed.Image.Url)">
<img class="chatlog__embed-generic-image" src="@await ResolveAssetUrlAsync(embed.Url)" alt="Embedded image" loading="lazy"> <img class="chatlog__embed-generic-image" src="@await ResolveAssetUrlAsync(embed.Image.ProxyUrl ?? embed.Image.Url)" alt="Embedded image" loading="lazy">
</a> </a>
</div> </div>
} }

Loading…
Cancel
Save