fix(embeds): animate GIF previews; add Mixcloud/Deezer; misc embed fixes
GIF previews rendered but never played: Synapse's /thumbnail endpoint flattens animated GIFs to a still first frame. GifCard and the generic OG card now request the original via /download (no width/height) for GIFs, so they animate. Guarded with shouldServeGifOriginal(): a matrix:image:size cap (10 MB) keeps a huge self-hosted GIF on the frozen thumbnail, and the generic card's eager <img> gains loading="lazy" (it was the one preview image missing it) so originals stay off the wire until near the viewport. Also adds Mixcloud + Deezer inline media embeds (iframe widgets via parseMediaEmbed/MediaEmbedCard, matching the existing click-to-play pattern), and fixes Deezer podcast links: they live at /show/<id>, not /podcast/<id> (the latter 404s on Deezer's own oEmbed) — verified against the live API. Reviewed by two agents; both findings (Deezer /show, GIF eager-load) fixed and covered by tests. Desktop Tauri frame-src CSP updated separately. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -549,6 +549,16 @@ export const BadgeTidal = style({
|
||||
color: '#ffffff',
|
||||
});
|
||||
|
||||
export const BadgeMixcloud = style({
|
||||
backgroundColor: '#52aad8',
|
||||
color: '#ffffff',
|
||||
});
|
||||
|
||||
export const BadgeDeezer = style({
|
||||
backgroundColor: '#a238ff',
|
||||
color: '#ffffff',
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Twitch LIVE badge
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -305,6 +305,32 @@ function isTenor(url: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
// Synapse's thumbnailer flattens animated images to a single still frame, so a
|
||||
// GIF served from /thumbnail renders but never plays. Detect GIF previews so the
|
||||
// card can point at /download (the original) instead.
|
||||
function isGifPreview(url: string, prev: IPreviewUrlResponse): boolean {
|
||||
if (prev['og:image:type'] === 'image/gif') return true;
|
||||
try {
|
||||
return new URL(url).pathname.toLowerCase().endsWith('.gif');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Ceiling on the /download upgrade below: a self-hosted GIF can be hundreds of
|
||||
// MB, and unlike a thumbnail it is served unscaled. Past the cap we keep the
|
||||
// (frozen) thumbnail — the card still links out, so the GIF is one click away.
|
||||
const GIF_ORIGINAL_MAX_BYTES = 10 * 1024 * 1024;
|
||||
|
||||
// Should this preview's image be fetched whole (so it animates) rather than
|
||||
// thumbnailed? Size is advisory: Synapse usually reports it, and when it's
|
||||
// absent we prefer a working animation over a hypothetical huge file.
|
||||
function shouldServeGifOriginal(url: string, prev: IPreviewUrlResponse): boolean {
|
||||
if (!isGifPreview(url, prev)) return false;
|
||||
const size = prev['matrix:image:size'];
|
||||
return typeof size !== 'number' || size <= GIF_ORIGINAL_MAX_BYTES;
|
||||
}
|
||||
|
||||
function getCardVariant(url: string): CardVariant {
|
||||
// NOTE: embeddable providers (YouTube/Vimeo/TikTok/Spotify/Twitch/…) are handled
|
||||
// upstream by parseMediaEmbed + MediaEmbedCard; getCardVariant only routes the
|
||||
@@ -1077,6 +1103,8 @@ const EMBED_BADGE: Record<string, { label: string; class: string }> = {
|
||||
bluesky: { label: 'Bluesky', class: previewCss.BadgeBluesky },
|
||||
loom: { label: 'Loom', class: previewCss.BadgeLoom },
|
||||
kick: { label: 'Kick', class: previewCss.BadgeKick },
|
||||
mixcloud: { label: 'Mixcloud', class: previewCss.BadgeMixcloud },
|
||||
deezer: { label: 'Deezer', class: previewCss.BadgeDeezer },
|
||||
};
|
||||
|
||||
// The homeserver preview for some sites (notably Reddit) comes back as a bot-check
|
||||
@@ -2081,8 +2109,13 @@ function GifCard({
|
||||
const title = (prev['og:title'] as string | undefined) ?? '';
|
||||
const mxcImage = prev['og:image'] as string | undefined;
|
||||
|
||||
// A GIF card exists to show a moving GIF, so request the original rather than
|
||||
// a thumbnail — the thumbnail endpoint would return a frozen first frame.
|
||||
// `loading="lazy"` below keeps it off the wire until it's near the viewport.
|
||||
const thumbSrc = mxcImage
|
||||
? mxcUrlToHttp(mx, mxcImage, useAuthentication, 400, 200, 'scale', false)
|
||||
? shouldServeGifOriginal(url, prev)
|
||||
? mxcUrlToHttp(mx, mxcImage, useAuthentication)
|
||||
: mxcUrlToHttp(mx, mxcImage, useAuthentication, 400, 200, 'scale', false)
|
||||
: null;
|
||||
|
||||
// If there's no image, fall back to a generic-style layout
|
||||
@@ -2180,6 +2213,7 @@ function GenericCard({
|
||||
src={displayThumb}
|
||||
alt={prev['og:title']}
|
||||
title={prev['og:title']}
|
||||
loading="lazy"
|
||||
tabIndex={0}
|
||||
onKeyDown={(evt) => onEnterOrSpace(() => onOpenViewer())(evt)}
|
||||
onClick={onOpenViewer}
|
||||
@@ -2349,16 +2383,11 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number }>(
|
||||
// Generic fallback — skip empty cards
|
||||
if (!prev['og:title'] && !prev['og:description']) return null;
|
||||
|
||||
const thumbUrl = mxcUrlToHttp(
|
||||
mx,
|
||||
prev['og:image'] || '',
|
||||
useAuthentication,
|
||||
256,
|
||||
256,
|
||||
'scale',
|
||||
false,
|
||||
);
|
||||
const imgUrl = mxcUrlToHttp(mx, prev['og:image'] || '', useAuthentication);
|
||||
// Show the original for GIFs so they animate; thumbnailing freezes them.
|
||||
const thumbUrl = shouldServeGifOriginal(url, prev)
|
||||
? imgUrl
|
||||
: mxcUrlToHttp(mx, prev['og:image'] || '', useAuthentication, 256, 256, 'scale', false);
|
||||
|
||||
return (
|
||||
<GenericCard
|
||||
|
||||
Reference in New Issue
Block a user