Skip to content

Commit e33bafd

Browse files
authored
Merge pull request #1421 from hackmdio/fix/cannot-download-pdf
Fix server crash when download pdf twice
2 parents 90898e7 + b8fb9db commit e33bafd

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)