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) {
|
} else if (attachment.url) {
|
||||||
const contentType = await fetch(attachment.url, {
|
let attUrl = attachment.url;
|
||||||
method: "HEAD",
|
if (Array.isArray(attachment.url)) {
|
||||||
}).then((res) => res.headers.get("Content-Type"));
|
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) {
|
||||||
if (contentType.startsWith("image/")) {
|
if (contentType.startsWith("image/")) {
|
||||||
images.push({
|
images.push({
|
||||||
url: attachment.url,
|
url: attUrl,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: contentType,
|
type: contentType,
|
||||||
});
|
});
|
||||||
} else if (contentType.startsWith("video/")) {
|
} else if (contentType.startsWith("video/")) {
|
||||||
videos.push({
|
videos.push({
|
||||||
url: attachment.url,
|
url: attUrl,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: contentType,
|
type: contentType,
|
||||||
});
|
});
|
||||||
} else if (contentType.startsWith("audio/")) {
|
} else if (contentType.startsWith("audio/")) {
|
||||||
audios.push({
|
audios.push({
|
||||||
url: attachment.url,
|
url: attUrl,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: contentType,
|
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");
|
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? type == "image" ? "png" : type == "video" ? "mp4" : "mpeg");
|
||||||
if (type.startsWith("image")) {
|
if (type.startsWith("image")) {
|
||||||
images.push({
|
images.push({
|
||||||
url: attachment.url,
|
url: attUrl,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
});
|
});
|
||||||
} else if (type.startsWith("video")) {
|
} else if (type.startsWith("video")) {
|
||||||
videos.push({
|
videos.push({
|
||||||
url: attachment.url,
|
url: attUrl,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
});
|
});
|
||||||
} else if (type.startsWith("audio")) {
|
} else if (type.startsWith("audio")) {
|
||||||
audios.push({
|
audios.push({
|
||||||
url: attachment.url,
|
url: attUrl,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue