mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 16:51:33 +10:00
Fix server crash when non-zip file is uploaded
This commit is contained in:
@ -35,6 +35,7 @@ export class IntegrationsService {
|
|||||||
|
|
||||||
async linkedIn(userId: number, path: string): Promise<ResumeEntity> {
|
async linkedIn(userId: number, path: string): Promise<ResumeEntity> {
|
||||||
let archive: StreamZip.StreamZipAsync;
|
let archive: StreamZip.StreamZipAsync;
|
||||||
|
let isArchiveValid = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
archive = new StreamZip.async({ file: path });
|
archive = new StreamZip.async({ file: path });
|
||||||
@ -48,6 +49,9 @@ export class IntegrationsService {
|
|||||||
slug: `imported-from-linkedin-${timestamp}`,
|
slug: `imported-from-linkedin-${timestamp}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if archive is valid
|
||||||
|
isArchiveValid = await archive.entries().then((entries) => Object.keys(entries).length > 0);
|
||||||
|
|
||||||
// Profile
|
// Profile
|
||||||
try {
|
try {
|
||||||
const profileCSV = (await archive.entryData('Profile.csv')).toString();
|
const profileCSV = (await archive.entryData('Profile.csv')).toString();
|
||||||
@ -261,7 +265,7 @@ export class IntegrationsService {
|
|||||||
throw new HttpException('You must upload a valid zip archive downloaded from LinkedIn.', HttpStatus.BAD_REQUEST);
|
throw new HttpException('You must upload a valid zip archive downloaded from LinkedIn.', HttpStatus.BAD_REQUEST);
|
||||||
} finally {
|
} finally {
|
||||||
await unlink(path);
|
await unlink(path);
|
||||||
!isEmpty(archive) && archive.close();
|
isArchiveValid && archive.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user