fedimbed: foiled by my own spec compliance

This commit is contained in:
Cynthia Foxwell 2025-04-17 22:31:54 -06:00
parent 72459f8dc4
commit ea63a96ec1
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -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,
});