diff --git a/src/internships/internships.controller.ts b/src/internships/internships.controller.ts index 3db74f04f2bddd9213935ca4e5cde9c0590260e7..58a18914f0cee611d391c4452336ef293d970a64 100644 --- a/src/internships/internships.controller.ts +++ b/src/internships/internships.controller.ts @@ -60,13 +60,19 @@ export class InternshipsController { // uploads even if invalid state... @Put(':studentId/:state') @UseInterceptors( - FileInterceptor('pdf', { + FileInterceptor('file', { storage: diskStorage({ destination: './files', filename: (_req, _file, cb) => { return cb(null, `${v4()}.pdf`); }, }), + fileFilter: (req, file, cb) => { + if (!file.originalname.match(/\.pdf$/)) { + return cb(new Error('Only PDF files are allowed!'), false); + } + cb(null, true); + }, }), ) updateState( diff --git a/src/resources/resources.controller.ts b/src/resources/resources.controller.ts index afd5df97a65ed6741e182a9a5984392acaa1bf95..332d8bb8f4227119da63c4ebbf01ad926d25bf5f 100644 --- a/src/resources/resources.controller.ts +++ b/src/resources/resources.controller.ts @@ -19,7 +19,7 @@ export class ResourcesController { @Param('filename') filename, @Res({ passthrough: true }) res: Response, ): StreamableFile { - const filepath = `files\\${filename}`; + const filepath = `files/${filename}`; if (!existsSync(filepath)) throw NOT_FOUND; const file = createReadStream(filepath); res.set({