Add timeouts to many projectlounge requests, fixed command bug

This commit is contained in:
Essem 2021-08-18 08:07:55 -05:00
parent 4684db06e8
commit 516570efe4
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
6 changed files with 60 additions and 22 deletions

View file

@ -118,8 +118,13 @@ module.exports = async (client, cluster, worker, ipc, message) => {
const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`;
await fs.promises.writeFile(`${process.env.TEMPDIR}/${filename}`, result.file);
const imageURL = `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}`;
const controller = new AbortController(); // eslint-disable-line no-undef
const timeout = setTimeout(() => {
controller.abort();
}, 5000);
try {
await fetch(imageURL);
await fetch(imageURL, { signal: controller.signal });
clearTimeout(timeout);
} catch {
// this is here to make sure the image is properly cached by discord
}