ngusidandon
This commit is contained in:
@@ -39,20 +39,7 @@ export class MinioService {
|
|||||||
'GET',
|
'GET',
|
||||||
this.configService.get('BUCKET_NAME') ?? 'epess',
|
this.configService.get('BUCKET_NAME') ?? 'epess',
|
||||||
`${category}/${id}`,
|
`${category}/${id}`,
|
||||||
3600,
|
0,
|
||||||
);
|
|
||||||
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,
|
|
||||||
);
|
);
|
||||||
return url;
|
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() {
|
fileName() {
|
||||||
// generate a unique file name using uuid
|
// generate a unique file name using uuid
|
||||||
return uuidv4();
|
return uuidv4();
|
||||||
|
|||||||
@@ -24,20 +24,36 @@ export class ResumeSchema extends PothosSchema {
|
|||||||
return this.builder.prismaObject('Resume', {
|
return this.builder.prismaObject('Resume', {
|
||||||
description: 'A resume in the system.',
|
description: 'A resume in the system.',
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.exposeID('id'),
|
id: t.exposeID('id', {
|
||||||
userId: t.exposeID('userId'),
|
description: 'The ID of the resume.',
|
||||||
centerId: t.exposeID('centerId'),
|
}),
|
||||||
status: t.exposeString('status'),
|
userId: t.exposeID('userId', {
|
||||||
|
description: 'The ID of the user.',
|
||||||
|
}),
|
||||||
|
centerId: t.exposeID('centerId', {
|
||||||
|
description: 'The ID of the center.',
|
||||||
|
}),
|
||||||
|
status: t.expose('status', {
|
||||||
|
type: ResumeStatus,
|
||||||
|
nullable: true,
|
||||||
|
description: 'The status of the resume.',
|
||||||
|
}),
|
||||||
createdAt: t.expose('createdAt', {
|
createdAt: t.expose('createdAt', {
|
||||||
type: 'DateTime',
|
type: 'DateTime',
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
description: 'The date and time the resume was created.',
|
||||||
}),
|
}),
|
||||||
updatedAt: t.expose('updatedAt', {
|
updatedAt: t.expose('updatedAt', {
|
||||||
type: 'DateTime',
|
type: 'DateTime',
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
description: 'The date and time the resume was updated.',
|
||||||
|
}),
|
||||||
|
center: t.relation('center', {
|
||||||
|
description: 'The center for the resume.',
|
||||||
|
}),
|
||||||
|
resumeFile: t.relation('ResumeFile', {
|
||||||
|
description: 'The resume file for the resume.',
|
||||||
}),
|
}),
|
||||||
center: t.relation('center'),
|
|
||||||
resumeFile: t.relation('ResumeFile'),
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -53,16 +69,8 @@ export class ResumeSchema extends PothosSchema {
|
|||||||
resumeId: t.exposeID('resumeId', {
|
resumeId: t.exposeID('resumeId', {
|
||||||
description: 'The ID of the resume.',
|
description: 'The ID of the resume.',
|
||||||
}),
|
}),
|
||||||
fileUrl: t.string({
|
fileUrl: t.exposeString('fileUrl', {
|
||||||
description: 'The URL of the resume file.',
|
description: 'The URL of the resume file.',
|
||||||
resolve: async (file, args, ctx) => {
|
|
||||||
// check if fileUrl is still valid
|
|
||||||
return await this.minioService.getNewFileUrl(
|
|
||||||
file.id,
|
|
||||||
'resumes',
|
|
||||||
file.fileUrl,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
actualFileName: t.exposeString('actualFileName', {
|
actualFileName: t.exposeString('actualFileName', {
|
||||||
description: 'The original name of the resume file.',
|
description: 'The original name of the resume file.',
|
||||||
|
|||||||
Reference in New Issue
Block a user