Changeset 28b59e7 in Klonkt


Ignore:
Timestamp:
06/30/2026 02:24:00 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
443f982
Parents:
292734a
Message:

fix(federation): don't federate inline images we can't serve (stale /images/... -> black tile in Mastodon)

buildNote turned every inline <img> into an AP image attachment, including a dead relative path
(e.g. a stale /images/<hash>.jpg that 404s). Mastodon then showed it as a black tile in its
attachment grid next to the real cover. Now only federate absolute http(s) URLs or our own
/media/ uploads; other relative paths (which we don't host) are skipped.

  • src/services/ActivityPubService.js — guard inline image collection in buildNote

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/ActivityPubService.js

    r292734a r28b59e7  
    232232  if (post.cover_image_url && !playable) urls.push(abs(post.cover_image_url));
    233233  let body = post.content || '';
    234   if (!playable) for (const m of body.matchAll(/<img\b[^>]*\bsrc="([^"]+)"[^>]*>/gi)) urls.push(abs(m[1]));
     234  // Only federate inline images we can actually serve: absolute http(s) URLs, or our own
     235  // /media/ uploads. A relative path we don't host (e.g. a stale /images/... ref) would 404
     236  // 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)) {
     238    const src = m[1];
     239    if (/^https?:\/\//i.test(src) || src.startsWith('/media/')) urls.push(abs(src));
     240  }
    235241  body = body.replace(/<img\b[^>]*>/gi, '');
    236242  // Audio shortcodes: do NOT federate the raw audio file — Klonkt deliberately
Note: See TracChangeset for help on using the changeset viewer.