fedimbed: we love non-standard activitystream implementations
This commit is contained in:
parent
60631bba37
commit
2388f0cc47
1 changed files with 73 additions and 71 deletions
|
@ -997,90 +997,92 @@ async function processUrl(msg, url, spoiler = false, command = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB: gts doesnt send singular attachments as array
|
if (postData.attachment) {
|
||||||
const attachments = Array.isArray(postData.attachment) ? postData.attachment : [postData.attachment];
|
// NB: gts doesnt send singular attachments as array
|
||||||
for (const attachment of attachments) {
|
const attachments = Array.isArray(postData.attachment) ? postData.attachment : [postData.attachment];
|
||||||
if (attachment.mediaType) {
|
for (const attachment of attachments) {
|
||||||
if (attachment.mediaType.startsWith("video/")) {
|
if (attachment.mediaType) {
|
||||||
videos.push({
|
if (attachment.mediaType.startsWith("video/")) {
|
||||||
url: attachment.url,
|
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
|
||||||
type: attachment.mediaType,
|
|
||||||
});
|
|
||||||
} else if (attachment.mediaType.startsWith("image/")) {
|
|
||||||
images.push({
|
|
||||||
url: attachment.url,
|
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
|
||||||
type: attachment.mediaType,
|
|
||||||
});
|
|
||||||
} else if (attachment.mediaType.startsWith("audio/")) {
|
|
||||||
audios.push({
|
|
||||||
url: attachment.url,
|
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
|
||||||
type: attachment.mediaType,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (attachment.url) {
|
|
||||||
const contentType = await fetch(attachment.url, {
|
|
||||||
method: "HEAD",
|
|
||||||
}).then((res) => res.headers.get("Content-Type"));
|
|
||||||
|
|
||||||
if (contentType) {
|
|
||||||
if (contentType.startsWith("image/")) {
|
|
||||||
images.push({
|
|
||||||
url: attachment.url,
|
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
|
||||||
type: contentType,
|
|
||||||
});
|
|
||||||
} else if (contentType.startsWith("video/")) {
|
|
||||||
videos.push({
|
videos.push({
|
||||||
url: attachment.url,
|
url: attachment.url,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: contentType,
|
type: attachment.mediaType,
|
||||||
});
|
});
|
||||||
} else if (contentType.startsWith("audio/")) {
|
} else if (attachment.mediaType.startsWith("image/")) {
|
||||||
|
images.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
|
type: attachment.mediaType,
|
||||||
|
});
|
||||||
|
} else if (attachment.mediaType.startsWith("audio/")) {
|
||||||
audios.push({
|
audios.push({
|
||||||
url: attachment.url,
|
url: attachment.url,
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
type: contentType,
|
type: attachment.mediaType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else if (attachment.url) {
|
||||||
|
const contentType = await fetch(attachment.url, {
|
||||||
|
method: "HEAD",
|
||||||
|
}).then((res) => res.headers.get("Content-Type"));
|
||||||
|
|
||||||
|
if (contentType) {
|
||||||
|
if (contentType.startsWith("image/")) {
|
||||||
|
images.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
|
type: contentType,
|
||||||
|
});
|
||||||
|
} else if (contentType.startsWith("video/")) {
|
||||||
|
videos.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
|
type: contentType,
|
||||||
|
});
|
||||||
|
} else if (contentType.startsWith("audio/")) {
|
||||||
|
audios.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
|
type: contentType,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const type = attachment.type?.toLowerCase();
|
||||||
|
|
||||||
|
const fileType =
|
||||||
|
type.indexOf("/") > -1
|
||||||
|
? type
|
||||||
|
: type +
|
||||||
|
"/" +
|
||||||
|
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? type == "image" ? "png" : type == "video" ? "mp4" : "mpeg");
|
||||||
|
if (type.startsWith("image")) {
|
||||||
|
images.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
|
type: fileType,
|
||||||
|
});
|
||||||
|
} else if (type.startsWith("video")) {
|
||||||
|
videos.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
|
type: fileType,
|
||||||
|
});
|
||||||
|
} else if (type.startsWith("audio")) {
|
||||||
|
audios.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
||||||
|
type: fileType,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const type = attachment.type?.toLowerCase();
|
logger.warn("fedimbed", `Unhandled attachment structure! ${JSON.stringify(attachment)}`);
|
||||||
|
|
||||||
const fileType =
|
|
||||||
type.indexOf("/") > -1
|
|
||||||
? type
|
|
||||||
: type +
|
|
||||||
"/" +
|
|
||||||
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? type == "image" ? "png" : type == "video" ? "mp4" : "mpeg");
|
|
||||||
if (type.startsWith("image")) {
|
|
||||||
images.push({
|
|
||||||
url: attachment.url,
|
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
|
||||||
type: fileType,
|
|
||||||
});
|
|
||||||
} else if (type.startsWith("video")) {
|
|
||||||
videos.push({
|
|
||||||
url: attachment.url,
|
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
|
||||||
type: fileType,
|
|
||||||
});
|
|
||||||
} else if (type.startsWith("audio")) {
|
|
||||||
audios.push({
|
|
||||||
url: attachment.url,
|
|
||||||
desc: attachment.name ?? attachment.description ?? attachment.comment,
|
|
||||||
type: fileType,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logger.warn("fedimbed", `Unhandled attachment structure! ${JSON.stringify(attachment)}`);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!spoiler && postData.sensitive && attachments.length > 0) {
|
if (!spoiler && postData.sensitive && attachments.length > 0) {
|
||||||
spoiler = true;
|
spoiler = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postData.image?.url) {
|
if (postData.image?.url) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue