diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index fac1ca9..6cf7197 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -1259,26 +1259,46 @@ async function processUrl(msg, url, spoiler = false, command = false) { }); } } else if (attachment.url) { - const contentType = await fetch(attachment.url, { - method: "HEAD", - }).then((res) => res.headers.get("Content-Type")); + let attUrl = attachment.url; + if (Array.isArray(attachment.url)) { + switch (attachment.type) { + case "Image": { + const newUrl = attachment.url.find((a) => a.mediaType?.startsWith("image/"))?.href; + if (newUrl) attUrl = newUrl; + break; + } + case "Video": { + const newUrl = attachment.url.find((a) => a.mediaType?.startsWith("video/"))?.href; + if (newUrl) attUrl = newUrl; + break; + } + default: + attUrl = attachment.url[0]?.href; + } + } + + let contentType; + if (attUrl != null) + contentType = await fetch(attUrl, { + method: "HEAD", + }).then((res) => res.headers.get("Content-Type")); if (contentType) { if (contentType.startsWith("image/")) { images.push({ - url: attachment.url, + url: attUrl, desc: attachment.name ?? attachment.description ?? attachment.comment, type: contentType, }); } else if (contentType.startsWith("video/")) { videos.push({ - url: attachment.url, + url: attUrl, desc: attachment.name ?? attachment.description ?? attachment.comment, type: contentType, }); } else if (contentType.startsWith("audio/")) { audios.push({ - url: attachment.url, + url: attUrl, desc: attachment.name ?? attachment.description ?? attachment.comment, type: contentType, }); @@ -1294,19 +1314,19 @@ async function processUrl(msg, url, spoiler = false, command = false) { (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? type == "image" ? "png" : type == "video" ? "mp4" : "mpeg"); if (type.startsWith("image")) { images.push({ - url: attachment.url, + url: attUrl, desc: attachment.name ?? attachment.description ?? attachment.comment, type: fileType, }); } else if (type.startsWith("video")) { videos.push({ - url: attachment.url, + url: attUrl, desc: attachment.name ?? attachment.description ?? attachment.comment, type: fileType, }); } else if (type.startsWith("audio")) { audios.push({ - url: attachment.url, + url: attUrl, desc: attachment.name ?? attachment.description ?? attachment.comment, type: fileType, });