feat: add s3 env variables to .env.example

This commit is contained in:
Ahmed Bouhuolia
2024-05-30 17:58:58 +02:00
parent 8ed24748ec
commit 7ff36e8c4f
5 changed files with 35 additions and 21 deletions

View File

@@ -1,23 +1,19 @@
import { Service } from 'typedi';
import { GetObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { s3 } from '@/lib/S3/S3';
import { Service } from 'typedi';
import config from '@/config';
@Service()
export class getAttachmentPresignedUrl {
/**
* Retrieves the presigned url of the given attachment key.
* @param {string} key
* @param {string} key
* @returns {Promise<string?>}
*/
async getPresignedUrl(key: string) {
const params = {
Bucket: process.env.AWS_BUCKET,
Key: key,
Expires: 60 * 5, // 5 minutes
};
const command = new GetObjectCommand({
Bucket: process.env.AWS_BUCKET,
Bucket: config.s3.bucket,
Key: key,
});
const signedUrl = await getSignedUrl(s3, command, { expiresIn: 300 });