From 6f8596a55f8b7d904e2e1a86dfb1081cd67b8dba Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Fri, 18 Apr 2025 18:20:13 -0600 Subject: [PATCH] fedimbed: attempt to fix images --- src/modules/fedimbed.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index ccae30d..5e26937 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -1062,20 +1062,21 @@ async function processUrl(msg, url, spoiler = false, command = false) { for (const attachment of attachments) { const type = attachment.type?.toLowerCase(); + const attDesc = attachment.description ?? attachment.comment; if (type.startsWith("image")) { images.push({ media: {url: attachment.url}, - description: attachment.description ?? attachment.comment, + description: attDesc?.length > 0 ? attDesc : null, }); } else if (type.startsWith("video")) { videos.push({ media: {url: attachment.url}, - description: attachment.description ?? attachment.comment, + description: attDesc?.length > 0 ? attDesc : null, }); } else if (type.startsWith("audio")) { audios.push({ url: attachment.url, - description: attachment.description ?? attachment.comment, + description: attDesc?.length > 0 ? attDesc : null, }); } } @@ -1142,7 +1143,7 @@ async function processUrl(msg, url, spoiler = false, command = false) { }) .then((res) => res.json()) .catch((err) => { - /*if (platform !== "cohost")*/ logger.error("fedimbed", `Failed to get author for "${url}": ${err}`); + logger.error("fedimbed", `Failed to get author for "${url}": ${err}`); }); if (authorData) { @@ -1186,20 +1187,21 @@ async function processUrl(msg, url, spoiler = false, command = false) { } } + const attDesc = attachment.name ?? attachment.description ?? attachment.comment; if (type.startsWith("image")) { images.push({ media: {url: attUrl}, - description: attachment.name ?? attachment.description ?? attachment.comment, + description: attDesc?.length > 0 ? attDesc : null, }); } else if (type.startsWith("video")) { videos.push({ media: {url: attUrl}, - description: attachment.name ?? attachment.description ?? attachment.comment, + description: attDesc?.length > 0 ? attDesc : null, }); } else if (type.startsWith("audio")) { audios.push({ url: attUrl, - description: attachment.name ?? attachment.description ?? attachment.comment, + description: attDesc?.length > 0 ? attDesc : null, }); } } else { @@ -1403,10 +1405,10 @@ async function processUrl(msg, url, spoiler = false, command = false) { return `> **${o.name}** (${numberFormatter.format(o.count)}, ${Math.round( percent * 100 - )}%)> \n\`${"\u2588".repeat(bar)}${" ".repeat(32 - bar)}\``; + )}%\n> \`${"\u2588".repeat(bar)}${" ".repeat(32 - bar)}\``; }) - .join("> \n> \n") + - `> \n> \n${poll.total} votes \u2022 End${pollTime > now ? "s" : "ed"} `, + .join("\n> \n> ") + + `\n> \n> ${poll.total} votes \u2022 End${pollTime > now ? "s" : "ed"} `, }); } @@ -1425,11 +1427,6 @@ async function processUrl(msg, url, spoiler = false, command = false) { url, }, }; - - for (const image in images) { - if (image.description?.length === 0) image.description = null; - } - if (images.length > 0) { if (images.length > 10) { while (images.length > 10) { @@ -1491,7 +1488,7 @@ async function processUrl(msg, url, spoiler = false, command = false) { return { response: { flags: 1 << 15, - components: [cw.length > 0 ? warningText : false, container].filter((x) => !!x), + components: [cw.length > 0 && warningText, container].filter((x) => !!x), allowedMentions: { repliedUser: false, },