From 5ab26c461fa00dd02600ae7291f3c56bbcba0c86 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Tue, 6 Dec 2022 17:01:44 -0700 Subject: [PATCH] fedimbed: fix attachments for mastoapi --- src/modules/fedimbed.js | 44 +++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 1c82879..9f8cbfa 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -182,10 +182,34 @@ async function processUrl(msg, url) { }; timestamp = postData2.created_at; for (const attachment of postData2.media_attachments) { - attachments.push({ - url: attachment.url, - desc: attachment.description, - }); + const fileType = + attachment.pleroma?.mime_type ?? + attachment.type + + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? + attachment.type == "image" + ? "png" + : attachment.type == "video" + ? "mp4" + : "mpeg"); + if (attachment.type == "image") { + images.push({ + url: attachment.url, + desc: attachment.description, + type: fileType, + }); + } else if (attachment.type == "video") { + videos.push({ + url: attachment.url, + desc: attachment.description, + type: fileType, + }); + } else if (attachment.type == "audio") { + audios.push({ + url: attachment.url, + desc: attachment.description, + type: fileType, + }); + } } } } @@ -261,7 +285,12 @@ async function processUrl(msg, url) { let desc = ""; let MAX_LENGTH = 3999; - if (cw != "" && (images.length == 0 && videos.length == 0 && audios.length == 0)) { + if ( + cw != "" && + images.length == 0 && + videos.length == 0 && + audios.length == 0 + ) { desc += "\u26a0 " + cw + "\n\n||" + content + "||"; MAX_LENGTH -= 8 - cw.length; } else { @@ -427,7 +456,10 @@ async function processUrl(msg, url) { .catch(() => {}); await msg.channel.createMessage({ - content: cw && (images.length > 0 || videos.length > 0 || audios.length > 0) ? `:warning: ${cw} || ${url} ||` : "", + content: + cw && (images.length > 0 || videos.length > 0 || audios.length > 0) + ? `:warning: ${cw} || ${url} ||` + : "", embeds, files, allowedMentions: {