From c4b57ac6176b95868de8e7773c973bff70063a76 Mon Sep 17 00:00:00 2001 From: TheEssem Date: Thu, 6 May 2021 22:01:30 -0500 Subject: [PATCH] Re-add a form of size limit --- classes/imageCommand.js | 4 ++++ utils/image.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/classes/imageCommand.js b/classes/imageCommand.js index 037c410..922858a 100644 --- a/classes/imageCommand.js +++ b/classes/imageCommand.js @@ -57,6 +57,10 @@ class ImageCommand extends Command { collections.runningCommands.delete(this.message.author.id); return this.constructor.noImage; } + if (image.type === "large") { + collections.runningCommands.delete(this.message.author.id); + return `${this.message.author.mention}, that image is too large!`; + } magickParams.path = image.path; magickParams.type = image.type; magickParams.url = image.url; // technically not required but can be useful for text filtering diff --git a/utils/image.js b/utils/image.js index fdfe4cc..a1df472 100644 --- a/utils/image.js +++ b/utils/image.js @@ -210,6 +210,10 @@ exports.getType = async (image) => { "Range": "bytes=0-1023" }}); clearTimeout(timeout); + if (parseInt(imageRequest.headers.get("Content-Range").split("/")[1]) > 20971520) { + type = "large"; + return type; + } const imageBuffer = await imageRequest.buffer(); const imageType = await fileType.fromBuffer(imageBuffer); if (imageType && formats.includes(imageType.mime)) {