Adapt max image file size to server boost tier, fixes #165

This commit is contained in:
Essem 2021-10-15 11:05:58 -05:00
parent c8d8973d7b
commit ab3ae7b9c6
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C

View file

@ -113,23 +113,38 @@ export default async (client, cluster, worker, ipc, message) => {
} else if (typeof result === "object" && result.embed) { } else if (typeof result === "object" && result.embed) {
await client.createMessage(message.channel.id, Object.assign(result, reference)); await client.createMessage(message.channel.id, Object.assign(result, reference));
} else if (typeof result === "object" && result.file) { } else if (typeof result === "object" && result.file) {
if (result.file.length > 8388119 && process.env.TEMPDIR !== "") { let fileSize = 8388119;
const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`; if (message.channel.guild) {
await promises.writeFile(`${process.env.TEMPDIR}/${filename}`, result.file); switch (message.channel.guild.premiumTier) {
const imageURL = `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}`; case 2:
await client.createMessage(message.channel.id, Object.assign({ fileSize = 52428308;
embed: { break;
color: 16711680, case 3:
title: "Here's your image!", fileSize = 104856616;
url: imageURL, break;
image: { default:
url: imageURL break;
}, }
footer: { }
text: "The result image was more than 8MB in size, so it was uploaded to an external site instead." if (result.file.length > fileSize) {
}, if (process.env.TEMPDIR !== "") {
} const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`;
}, reference)); await promises.writeFile(`${process.env.TEMPDIR}/${filename}`, result.file);
const imageURL = `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}`;
await client.createMessage(message.channel.id, Object.assign({
embed: {
color: 16711680,
title: "Here's your image!",
url: imageURL,
image: {
url: imageURL
},
footer: {
text: "The result image was more than 8MB in size, so it was uploaded to an external site instead."
},
}
}, reference));
}
} else { } else {
await client.createMessage(message.channel.id, Object.assign({ await client.createMessage(message.channel.id, Object.assign({
content: result.text ? result.text : undefined content: result.text ? result.text : undefined