From 2e43683835225230f4b9b4b7dd873f02f63edd6d Mon Sep 17 00:00:00 2001 From: Lucas Tomasi Date: Sun, 6 Oct 2024 15:42:17 -0300 Subject: [PATCH] Fix duplicate file upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, we face an issue when a file with the same name is uploaded more than once: 1.⁠ ⁠It results in a unique key error in the database. 2.⁠ ⁠If the file is sent to S3, it overwrites the old file. To resolve this problem, I've implemented a solution where we concatenate the message ID to the filename. This approach ensures uniqueness for each uploaded file, even if users upload files with identical names multiple times in a chat. This change allows normal users to upload files with the same name multiple times in a chat without encountering errors or unintended file overwrites. --- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 1da37deb..2e4c14ac 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1992,7 +1992,7 @@ export class BaileysStartupService extends ChannelStartupService { const mimetype = mime.getType(fileName).toString(); - const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, mediaType, fileName); + const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, `${messageRaw.key.id}`, mediaType, fileName); await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype,