Fix duplicate file upload

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.
This commit is contained in:
Lucas Tomasi 2024-10-06 15:42:17 -03:00 committed by GitHub
parent ebbba7b7e9
commit 2e43683835
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,