Changeset e091add in Klonkt for src/routes/posts.js


Ignore:
Timestamp:
06/30/2026 10:32:20 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
5f3f9ec
Parents:
f3663e5
Message:

feat(feed): embed PeerTube videos in the News feed

A federated PeerTube link (/w/<id> or /videos/watch/<id>, any instance) now renders as an inline
player in the feed, next to the YouTube/Spotify/SoundCloud/Vimeo/Bandcamp/Apple embeds. PeerTube is
decentralised, so it's matched by its watch-URL pattern (host validated for safe iframe-src) rather
than a fixed domain, and embeds to <host>/videos/embed/<id>. CSP frame-src 'self' https: already
allows it; added only in the feed builder (not the shared detectProvider).

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    rf3663e5 re091add  
    666666    const u = m[1]; if (seen.has(u)) continue; seen.add(u);
    667667    let p; try { p = AudioEmbedService.detectProvider(u); } catch { p = null; }
    668     if (!p) continue;
     668    if (!p) {
     669      // PeerTube is decentralised (any instance), so it's not in detectProvider — match its watch URL
     670      // (/w/<id> or /videos/watch/<id>) and embed the player. Host is validated (safe chars only), so
     671      // it's safe to inline into the iframe src; a non-PeerTube /w/ URL just yields an empty iframe.
     672      const pt = u.match(/^https?:\/\/([\w.-]+(?::\d+)?)\/(?:w|videos\/watch)\/([\w-]{6,})/i);
     673      if (pt) return `<iframe class="tl-embed-frame" src="https://${pt[1]}/videos/embed/${pt[2]}" title="PeerTube" loading="lazy" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>`;
     674      continue;
     675    }
    669676    if (p.provider === 'youtube') return `<iframe class="tl-embed-frame" src="https://www.youtube-nocookie.com/embed/${p.id}" title="YouTube" loading="lazy" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;
    670677    if (p.provider === 'spotify') return `<iframe class="tl-embed-frame tl-embed-spotify" src="https://open.spotify.com/embed/${p.type}/${p.id}" title="Spotify" loading="lazy" frameborder="0" allow="encrypted-media"></iframe>`;
Note: See TracChangeset for help on using the changeset viewer.