From b8fb9dbb9e2faee46edd57f85edae67980626040 Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Thu, 27 Feb 2020 00:02:18 +0800 Subject: [PATCH] fix: download pdf twice may crash server Signed-off-by: BoHong Li --- lib/note/noteActions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/note/noteActions.js b/lib/note/noteActions.js index 90f23f69..31f7c1f4 100644 --- a/lib/note/noteActions.js +++ b/lib/note/noteActions.js @@ -95,8 +95,11 @@ function actionPDF (req, res, note) { res.setHeader('Cache-Control', 'private') res.setHeader('Content-Type', 'application/pdf; charset=UTF-8') res.setHeader('X-Robots-Tag', 'noindex, nofollow') // prevent crawling + stream.on('end', () => { + stream.close() + fs.unlinkSync(pdfPath) + }) stream.pipe(res) - fs.unlinkSync(pdfPath) }) }