fedimbed: support posts with >4 images (up to 18)
This commit is contained in:
parent
c4f8d53321
commit
4bbe1a89d2
1 changed files with 101 additions and 6 deletions
|
@ -637,12 +637,107 @@ async function processUrl(msg, url, spoiler = false) {
|
||||||
const embeds = [];
|
const embeds = [];
|
||||||
|
|
||||||
if (images.length > 0) {
|
if (images.length > 0) {
|
||||||
for (const attachment of images) {
|
if (images.length == 4) {
|
||||||
const embed = Object.assign({}, baseEmbed);
|
for (const attachment of images) {
|
||||||
embed.image = {
|
const embed = Object.assign({}, baseEmbed);
|
||||||
url: attachment.url,
|
embed.image = {
|
||||||
};
|
url: attachment.url,
|
||||||
embeds.push(embed);
|
};
|
||||||
|
embeds.push(embed);
|
||||||
|
}
|
||||||
|
} else if (images.length > 4 && images.length <= 10) {
|
||||||
|
for (const attachment of images) {
|
||||||
|
const size = await fetch(attachment.url, {
|
||||||
|
method: "HEAD",
|
||||||
|
headers: {
|
||||||
|
"User-Agent": FRIENDLY_USERAGENT,
|
||||||
|
},
|
||||||
|
}).then((res) => Number(res.headers.get("Content-Length")));
|
||||||
|
|
||||||
|
if (size <= getUploadLimit(msg.channel.guild)) {
|
||||||
|
const file = await fetch(attachment.url, {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": FRIENDLY_USERAGENT,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => res.arrayBuffer())
|
||||||
|
.then((buf) => Buffer.from(buf));
|
||||||
|
|
||||||
|
files.push({
|
||||||
|
filename:
|
||||||
|
(cw != "" || spoiler ? "SPOILER_" : "") +
|
||||||
|
(attachment.type.indexOf("/") > -1
|
||||||
|
? attachment.type.replace("/", ".")
|
||||||
|
: attachment.type +
|
||||||
|
"." +
|
||||||
|
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "png")),
|
||||||
|
file,
|
||||||
|
description: attachment.desc,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
embeds.push(baseEmbed);
|
||||||
|
} else {
|
||||||
|
const ten = images.slice(0, 10);
|
||||||
|
|
||||||
|
for (const attachment of ten) {
|
||||||
|
const size = await fetch(attachment.url, {
|
||||||
|
method: "HEAD",
|
||||||
|
headers: {
|
||||||
|
"User-Agent": FRIENDLY_USERAGENT,
|
||||||
|
},
|
||||||
|
}).then((res) => Number(res.headers.get("Content-Length")));
|
||||||
|
|
||||||
|
if (size <= getUploadLimit(msg.channel.guild)) {
|
||||||
|
const file = await fetch(attachment.url, {
|
||||||
|
headers: {
|
||||||
|
"User-Agent": FRIENDLY_USERAGENT,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => res.arrayBuffer())
|
||||||
|
.then((buf) => Buffer.from(buf));
|
||||||
|
|
||||||
|
files.push({
|
||||||
|
filename:
|
||||||
|
(cw != "" || spoiler ? "SPOILER_" : "") +
|
||||||
|
(attachment.type.indexOf("/") > -1
|
||||||
|
? attachment.type.replace("/", ".")
|
||||||
|
: attachment.type +
|
||||||
|
"." +
|
||||||
|
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "png")),
|
||||||
|
file,
|
||||||
|
description: attachment.desc,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (images.length <= 14) {
|
||||||
|
const fourteen = images.slice(10, Math.min(images.length, 14));
|
||||||
|
|
||||||
|
for (const attachment of fourteen) {
|
||||||
|
const embed = Object.assign({}, baseEmbed);
|
||||||
|
embed.image = {
|
||||||
|
url: attachment.url,
|
||||||
|
};
|
||||||
|
embeds.push(embed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (images.length <= 18) {
|
||||||
|
const eighteen = images.slice(14, Math.min(images.length, 18));
|
||||||
|
const _embed = {
|
||||||
|
url: baseEmbed.url + "?_",
|
||||||
|
title: "Additional Images",
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const attachment of eighteen) {
|
||||||
|
const embed = Object.assign({}, _embed);
|
||||||
|
embed.image = {
|
||||||
|
url: attachment.url,
|
||||||
|
};
|
||||||
|
embeds.push(embed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
embeds.push(baseEmbed);
|
embeds.push(baseEmbed);
|
||||||
|
|
Loading…
Reference in a new issue