Changeset 443f982 in Klonkt
- Timestamp:
- 06/30/2026 02:37:32 PM (2 months ago)
- Branches:
- main
- Children:
- 1a0b007
- Parents:
- 28b59e7
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r28b59e7 r443f982 21 21 import db from '../config/database.js'; 22 22 import HtmlSanitizerService from './HtmlSanitizerService.js'; 23 import AudioEmbedService from './AudioEmbedService.js'; 23 24 24 25 const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; … … 225 226 const hadAudio = /\[\[(track|album|playlist):/i.test(post.content || ''); 226 227 const playable = hasPlayableAudio(post.content || '', site && site.id); 228 // A post with an external embed (Spotify/YouTube/SoundCloud/Vimeo/Bandcamp/Apple) should let 229 // Mastodon render the embed's player CARD. Mastodon shows EITHER media attachments OR a link 230 // card, never both — so when the post has an embed link we skip the image attachments so the 231 // card wins. (On Klonkt nothing changes: the cover + the embed player still render.) 232 const hasEmbed = (() => { 233 const c = post.content || ''; 234 if (/\[\[embed:/i.test(c)) return true; 235 for (const m of c.matchAll(/https?:\/\/[^\s"'<>]+/gi)) if (AudioEmbedService.detectProvider(m[0])) return true; 236 return false; 237 })(); 238 const noImages = playable || hasEmbed; // suppress image attachments → let the player/embed card show 227 239 const urls = []; 228 240 // Posts with PLAYABLE hosted audio suppress image attachments so Mastodon renders … … 230 242 // link/player card are mutually exclusive on Mastodon. Link-only audio (external) 231 243 // keeps its cover (no player card to show). 232 if (post.cover_image_url && ! playable) urls.push(abs(post.cover_image_url));244 if (post.cover_image_url && !noImages) urls.push(abs(post.cover_image_url)); 233 245 let body = post.content || ''; 234 246 // Only federate inline images we can actually serve: absolute http(s) URLs, or our own 235 247 // /media/ uploads. A relative path we don't host (e.g. a stale /images/... ref) would 404 236 248 // and show up as a black tile in Mastodon's attachment grid. 237 if (! playable) for (const m of body.matchAll(/<img\b[^>]*\bsrc="([^"]+)"[^>]*>/gi)) {249 if (!noImages) for (const m of body.matchAll(/<img\b[^>]*\bsrc="([^"]+)"[^>]*>/gi)) { 238 250 const src = m[1]; 239 251 if (/^https?:\/\//i.test(src) || src.startsWith('/media/')) urls.push(abs(src));
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)