From 428b6e730a724c6d7822e21e930ba6bba3d77676 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 19 Jan 2026 21:37:23 -0500 Subject: [PATCH] fix: replace attachment generation logic in notes.public Previously, the logic retrieved the list of uploads, checked if they were thumbs, and set attachment (and noteAttachment) depending on object type. It was complicated and didn't really work so well, so I simplified it. Now thumbs.get is called, and attachment is appended with all thumbs and uploads. Sizing is not provided. Maybe later. Image is also now set, which is the first image in attachment. --- src/activitypub/mocks.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index 051b17f96e..19a20991c1 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -734,20 +734,12 @@ Mocks.notes.public = async (post) => { // Special handling for main posts (as:Article w/ as:Note preview) const plaintext = posts.sanitizePlaintext(content); const isArticle = post.pid === post.topic.mainPid && plaintext.length > 500; - const noteAttachment = isArticle ? [...attachment] : null; - const [uploads, thumbs] = await Promise.all([ - posts.uploads.listWithSizes(post.pid), - topics.getTopicField(post.tid, 'thumbs'), - ]); - const isThumb = uploads.map(u => Array.isArray(thumbs) ? thumbs.includes(u.name) : false); - uploads.forEach(({ name, width, height }, idx) => { + const thumbs = await topics.thumbs.get(post.tid); + thumbs.forEach(({ name, path }) => { const mediaType = mime.getType(name); - const url = `${nconf.get('url') + nconf.get('upload_url')}/${name}`; - (noteAttachment || attachment).push({ mediaType, url, width, height }); - if (isThumb[idx] && noteAttachment) { - attachment.push({ mediaType, url, width, height }); - } + const url = `${nconf.get('url') + nconf.get('upload_url')}${path}`; + attachment.push({ mediaType, url }); }); // Inspect post content for external imagery as well @@ -757,13 +749,14 @@ Mocks.notes.public = async (post) => { const { hostname, pathname, href: url } = new URL(match[1]); if (hostname !== nconf.get('url_parsed').hostname) { const mediaType = mime.getType(pathname); - (noteAttachment || attachment).push({ mediaType, url }); + attachment.push({ mediaType, url }); } } match = posts.imgRegex.exec(post.content); } attachment = normalizeAttachment(attachment); + const image = attachment.filter(entry => entry.type === 'Image')?.shift(); let preview; let summary = null; if (isArticle) { @@ -772,7 +765,7 @@ Mocks.notes.public = async (post) => { attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`, content: post.content, published, - attachment: normalizeAttachment(noteAttachment), + attachment, }; const sentences = tokenizer.sentences(post.content, { newline_boundaries: true }); @@ -833,6 +826,7 @@ Mocks.notes.public = async (post) => { source, tag, attachment, + image, replies: `${id}/replies`, };