fedimbed: foiled by my own spec compliance
This commit is contained in:
parent
72459f8dc4
commit
ea63a96ec1
1 changed files with 29 additions and 9 deletions
|
@ -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,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue