Skip to content

Possibility to ignore bucket policy and fix for repeated file name. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, mediaType, v4().replace(/-/g, ""), fileName);
await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, {
'Content-Type': mimetype,
});
Expand Down
5 changes: 5 additions & 0 deletions src/api/integrations/storage/s3/libs/minio.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
2 changes: 2 additions & 0 deletions src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export type S3 = {
ENABLE: boolean;
PORT?: number;
USE_SSL?: boolean;
IGNORE_POLICY?: boolean;
REGION?: string;
};

Expand Down Expand Up @@ -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?.S3_IGNORE_POLICY === 'true',
REGION: process.env?.S3_REGION,
},
AUTHENTICATION: {
Expand Down