From 33e6c6795aa4108529f58c6d74886b95789bb090 Mon Sep 17 00:00:00 2001 From: Paulo Victor Lund Date: Fri, 14 Feb 2025 13:28:22 -0300 Subject: [PATCH 1/4] Bucket IGNORE_POLICY --- src/api/integrations/storage/s3/libs/minio.server.ts | 5 +++++ src/config/env.config.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/api/integrations/storage/s3/libs/minio.server.ts b/src/api/integrations/storage/s3/libs/minio.server.ts index 5a66305c..40268f60 100644 --- a/src/api/integrations/storage/s3/libs/minio.server.ts +++ b/src/api/integrations/storage/s3/libs/minio.server.ts @@ -64,6 +64,11 @@ const createBucket = async () => { await minioClient.makeBucket(bucketName); } + if (BUCKET?.IGNORE_POLICY) { + logger.info(`S3 Bucket ${bucketName} - ON`); + return true; + } + await setBucketPolicy(); logger.info(`S3 Bucket ${bucketName} - ON`); diff --git a/src/config/env.config.ts b/src/config/env.config.ts index a46fb2aa..381fd544 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -249,6 +249,7 @@ export type S3 = { ENABLE: boolean; PORT?: number; USE_SSL?: boolean; + IGNORE_POLICY?: boolean; REGION?: string; }; @@ -552,6 +553,7 @@ export class ConfigService { ENABLE: process.env?.S3_ENABLED === 'true', PORT: Number.parseInt(process.env?.S3_PORT || '9000'), USE_SSL: process.env?.S3_USE_SSL === 'true', + IGNORE_POLICY: process.env?.IGNORE_POLICY === 'true', REGION: process.env?.S3_REGION, }, AUTHENTICATION: { From 98e618805be6c3e23b0794cfdc76dcfa808d254f Mon Sep 17 00:00:00 2001 From: Paulo Victor Lund Date: Fri, 14 Feb 2025 13:44:40 -0300 Subject: [PATCH 2/4] Update whatsapp.baileys.service.ts --- .../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 ddd93603..69cb0f07 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1030,7 +1030,7 @@ export class BaileysStartupService extends ChannelStartupService { const { buffer, mediaType, fileName, size } = media; const mimetype = mimeTypes.lookup(fileName).toString(); - const fullName = join(`${this.instance.id}`, received.key.remoteJid, mediaType, fileName); + const fullName = join(`${this.instance.id}`, received.key.remoteJid, v4().replace(/-/g, ""), mediaType, fileName); await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype, }); From cdb98dfc47548287494312ddf0867d978de75dac Mon Sep 17 00:00:00 2001 From: Paulo Victor Lund Date: Fri, 14 Feb 2025 13:46:15 -0300 Subject: [PATCH 3/4] unique file name --- .../integrations/channel/evolution/evolution.channel.service.ts | 2 +- .../integrations/channel/whatsapp/whatsapp.baileys.service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/integrations/channel/evolution/evolution.channel.service.ts b/src/api/integrations/channel/evolution/evolution.channel.service.ts index 7662fa24..d5a1a79a 100644 --- a/src/api/integrations/channel/evolution/evolution.channel.service.ts +++ b/src/api/integrations/channel/evolution/evolution.channel.service.ts @@ -400,7 +400,7 @@ export class EvolutionStartupService extends ChannelStartupService { const size = buffer.byteLength; - const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, mediaType, fileName); + const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, mediaType, v4().replace(/-/g, ""), fileName); await s3Service.uploadFile(fullName, buffer, size, { 'Content-Type': mimetype, diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 69cb0f07..6c4e9c93 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1030,7 +1030,7 @@ export class BaileysStartupService extends ChannelStartupService { const { buffer, mediaType, fileName, size } = media; const mimetype = mimeTypes.lookup(fileName).toString(); - const fullName = join(`${this.instance.id}`, received.key.remoteJid, v4().replace(/-/g, ""), mediaType, fileName); + const fullName = join(`${this.instance.id}`, received.key.remoteJid, mediaType, v4().replace(/-/g, ""), fileName); await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, { 'Content-Type': mimetype, }); From 2f90d4d03ef5e4b2e26b4f4509dd702714c6669a Mon Sep 17 00:00:00 2001 From: Paulo Victor Lund Date: Fri, 14 Feb 2025 13:50:43 -0300 Subject: [PATCH 4/4] typo fix --- .env.example | 1 + src/config/env.config.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index a3f438ea..0888b748 100644 --- a/.env.example +++ b/.env.example @@ -205,6 +205,7 @@ S3_PORT=443 S3_ENDPOINT=s3.domain.com S3_REGION=eu-west-3 S3_USE_SSL=true +S3_IGNORE_POLICY=false # AMAZON S3 - Environment variables # S3_ENABLED=true diff --git a/src/config/env.config.ts b/src/config/env.config.ts index 381fd544..09c7c382 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -553,7 +553,7 @@ export class ConfigService { ENABLE: process.env?.S3_ENABLED === 'true', PORT: Number.parseInt(process.env?.S3_PORT || '9000'), USE_SSL: process.env?.S3_USE_SSL === 'true', - IGNORE_POLICY: process.env?.IGNORE_POLICY === 'true', + IGNORE_POLICY: process.env?.S3_IGNORE_POLICY === 'true', REGION: process.env?.S3_REGION, }, AUTHENTICATION: {