Merge pull request #1421 from hackmdio/fix/cannot-download-pdf

Fix server crash when download pdf twice
This commit is contained in:
Max Wu 2020-02-27 00:31:51 +08:00 committed by GitHub
commit e33bafd35d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -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)
})
}