Skip to content

Commit

Permalink
✔ File Name ~
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Jan 21, 2024
1 parent 5d97b1d commit af15289
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/main-site/server/main.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,13 @@ export class AttachmentController {
} catch (e) {
this.gs.log('[DDL-ERROR] 💽', e, 'error');
}
const ddl = await this.aws.getDdl(resSaveAttachment.aws_s3, user, expiredSeconds);
const ddl = await this.aws.getDdl(
resSaveAttachment.aws_s3,
user,
expiredSeconds,
resSaveAttachment.orig,
resSaveAttachment.mime
);
res.redirect(301, ddl.toString());
} else {
const files = readdirSync(`${environment.uploadFolder}`, { withFileTypes: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ export class DdlGenerateController {
} catch (e) {
this.gs.log('[DDL-ERROR] 💽', e, 'error');
}
const ddl = await this.aws.getDdl(resSaveAttachment.aws_s3, user, expiredSeconds);
const ddl = await this.aws.getDdl(
resSaveAttachment.aws_s3,
user, expiredSeconds,
resSaveAttachment.orig,
resSaveAttachment.mime
);
res.status(HttpStatus.OK).json(classToPlain({
info: `😅 200 - DDL File API :: Generate URL 🤣`,
result: resSaveAttachment,
Expand Down
13 changes: 10 additions & 3 deletions projects/main-site/src/api/services/amazon-web.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class AmazonWebService {
});
}

async getDdl(fileName: string, user: UserModel, expiredSeconds = CONSTANTS.timeDdlS3): Promise<URL> {
async getDdl(fileName: string, user: UserModel, expiredSeconds = CONSTANTS.timeDdlS3, customFileName = null, customMimeType = null): Promise<URL> {
if (fileName.startsWith('http://')) {
fileName = fileName.slice(7, fileName.length);
} else if (fileName.startsWith('https://')) {
Expand All @@ -48,11 +48,18 @@ export class AmazonWebService {
if (fileName.startsWith(directLink2)) {
fileName = fileName.slice(directLink2.length, fileName.length);
}
const ddl = await this.s3().getSignedUrlPromise('getObject', {
const optParam: any = {
Bucket: bucketName,
Key: fileName,
Expires: expiredSeconds
});
};
if (customFileName) {
optParam.ResponseContentDisposition = `attachment; filename ="${customFileName}"`;
}
if (customMimeType) {
optParam.ResponseContentType = customMimeType;
}
const ddl = await this.s3().getSignedUrlPromise('getObject', optParam);
const uri = new URL(ddl);
const url = new URL(`https://${bucketName}/${fileName}`);
const sp = ['AWSAccessKeyId', 'Expires', 'Signature'];
Expand Down

0 comments on commit af15289

Please sign in to comment.