import { UploadFile , DeleteFile } from '@/domain/contracts/gateways' ; import { config , S3 } from 'aws-sdk' ; export class AwsS3FileStorage implements UploadFile , DeleteFile { constructor ( accessKey , secret , private readonly bucket ) { config . update ( { credentials : { accessKeyId : accessKey , secretAccessKey : secret } } ) ; } async upload ( { fileName , file } ) { await new S3 ( ) . putObject ( { Bucket : this . bucket , Key : fileName , Body : file , ACL : 'public-read' } ) . promise ( ) ; return `https://${ this . bucket }.s3.amazonaws.com/${ encodeURIComponent ( fileName ) }` ; } async delete ( { fileName } ) { await new S3 ( ) . deleteObject ( { Bucket : this . bucket , Key : fileName } ) . promise ( ) ; } }