fedimbed: upload audio files as well

This commit is contained in:
Cynthia Foxwell 2022-12-06 10:58:57 -07:00
parent bd82f1167c
commit 296886746a
1 changed files with 28 additions and 1 deletions

View File

@ -378,7 +378,34 @@ async function processUrl(msg, url) {
.then((buf) => Buffer.from(buf));
files.push({
name: "video." + attachment.type.split("/")[1],
name: attachment.type.replace("/", "."),
contents: file,
});
}
}
}
if (audios.length > 0) {
for (const attachment of audios) {
const size = await fetch(attachment.url, {
method: "HEAD",
headers: {
"User-Agent": FRIENDLY_USERAGENT,
},
})
.then((res) => res.blob())
.then((blob) => blob.size);
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({
name: attachment.type.replace("/", "."),
contents: file,
});
}