ngusidandon

This commit is contained in:
2024-10-18 14:54:31 +07:00
parent 1523642b9d
commit 99b3b19194
2 changed files with 24 additions and 46 deletions

View File

@@ -39,20 +39,7 @@ export class MinioService {
'GET',
this.configService.get('BUCKET_NAME') ?? 'epess',
`${category}/${id}`,
3600,
);
return url;
}
async getNewFileUrl(id: string, category: string, fileUrl: string) {
if (await this.checkFileUrl(fileUrl)) {
return fileUrl;
}
const url = await this.minioClient.presignedUrl(
'GET',
this.configService.get('BUCKET_NAME') ?? 'epess',
`${category}/${id}`,
3600,
0,
);
return url;
}
@@ -64,23 +51,6 @@ export class MinioService {
);
}
async checkFileUrl(fileUrl: string) {
// check if the file url is still valid by get X-Amz-Date= from the url and X-Amz-Expires from the url and compare with the current time
const url = new URL(fileUrl);
const _xAmzDate = url.searchParams.get('X-Amz-Date');
const _xAmzExpires = url.searchParams.get('X-Amz-Expires');
if (!_xAmzDate || !_xAmzExpires) {
return false;
}
const __xAmzDate = new Date(_xAmzDate);
const __xAmzExpires = new Date(
__xAmzDate.getTime() + parseInt(_xAmzExpires),
);
const currentTime = new Date();
return currentTime.getTime() < __xAmzExpires.getTime(); // true if the file url is still valid
}
//
fileName() {
// generate a unique file name using uuid
return uuidv4();