From 883d8adf933cf155d6bb6a5412acd81810fddcf7 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 17 Aug 2020 11:26:06 +0300 Subject: [PATCH] Fix crash when a user sends an attachment Also added an eslint rule to catch similar errors caused by shadowed variables in the future. --- .eslintrc | 3 ++- src/data/Thread.js | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index 6698909..437180d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,6 +20,7 @@ "!!": true } }], - "quotes": ["error", "double"] + "quotes": ["error", "double"], + "no-shadow": "error" } } diff --git a/src/data/Thread.js b/src/data/Thread.js index f27359f..87e407a 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -258,8 +258,8 @@ class Thread { let messageContent = msg.content || ""; // Prepare attachments - const attachments = []; - const smallAttachments = []; + const attachmentLinks = []; + const smallAttachmentLinks = []; const attachmentFiles = []; for (const attachment of msg.attachments) { @@ -269,10 +269,10 @@ class Thread { if (config.relaySmallAttachmentsAsAttachments && attachment.size <= config.smallAttachmentLimit) { const file = await attachments.attachmentToDiscordFileObject(attachment); attachmentFiles.push(file); - smallAttachments.push(savedAttachment.url); + smallAttachmentLinks.push(savedAttachment.url); } - attachments.push(savedAttachment.url); + attachmentLinks.push(savedAttachment.url); } // Handle special embeds (listening party invites etc.) @@ -311,8 +311,8 @@ class Thread { is_anonymous: 0, dm_message_id: msg.id, dm_channel_id: msg.channel.id, - attachments, - small_attachments: smallAttachments, + attachments: attachmentLinks, + small_attachments: smallAttachmentLinks, }); threadMessage = await this._addThreadMessageToDB(threadMessage.getSQLProps());