Skip to content

Commit

Permalink
feat: subject possibilidade de parâmetrizar o bucket do aws e o camii…
Browse files Browse the repository at this point in the history
…nho do arquivo por session
  • Loading branch information
fnevesgx committed May 19, 2023
1 parent 3813435 commit 32332d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Expand Up @@ -12,6 +12,7 @@ export default {
url: null,
autoDownload: true,
uploadS3: false,
awsBucketName: '',
readMessage: true,
allUnreadOnStart: false,
listenAcks: true,
Expand Down
16 changes: 12 additions & 4 deletions src/util/functions.ts
Expand Up @@ -24,12 +24,12 @@ import { promisify } from 'util';
import config from '../config';
import { convert } from '../mapper/index';
import { ServerOptions } from '../types/ServerOptions';
import aws from 'aws-sdk';

let mime: any, crypto: any, aws: any;
let mime: any, crypto: any; //, aws: any;
if (config.webhook.uploadS3) {
mime = config.webhook.uploadS3 ? mimetypes : null;
crypto = config.webhook.uploadS3 ? Crypto : null;
aws = config.webhook.uploadS3 ? import('aws-sdk') : null;
}

export function contactToArray(number: any, isGroup?: boolean) {
Expand Down Expand Up @@ -135,12 +135,20 @@ async function autoDownload(client: any, req: any, message: any) {
const buffer = await client.decryptFile(message);
if (req.serverOptions.webhook.uploadS3) {
const hashName = crypto.randomBytes(24).toString('hex');
const fileName = `${hashName}.${mime.extension(message.mimetype)}`;

const s3 = new aws.S3();
const bucketName =
config.webhook.awsBucketName && config.webhook.awsBucketName !== ''
? config.webhook.awsBucketName
: client.session;
const fileName = `${
config.webhook.awsBucketName && config.webhook.awsBucketName !== ''
? client.session + '/'
: ''
}${hashName}.${mime.extension(message.mimetype)}`;

const params = {
Bucket: client.session,
Bucket: bucketName,
Key: fileName,
Body: buffer,
ACL: 'public-read',
Expand Down

0 comments on commit 32332d0

Please sign in to comment.