Skip to content

Commit b8fb9db

Browse files
committed
fix: download pdf twice may crash server
Signed-off-by: BoHong Li <[email protected]>
1 parent 90898e7 commit b8fb9db

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/note/noteActions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ function actionPDF (req, res, note) {
9595
res.setHeader('Cache-Control', 'private')
9696
res.setHeader('Content-Type', 'application/pdf; charset=UTF-8')
9797
res.setHeader('X-Robots-Tag', 'noindex, nofollow') // prevent crawling
98+
stream.on('end', () => {
99+
stream.close()
100+
fs.unlinkSync(pdfPath)
101+
})
98102
stream.pipe(res)
99-
fs.unlinkSync(pdfPath)
100103
})
101104
}
102105

0 commit comments

Comments
 (0)