fix: download pdf twice may crash server

Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
BoHong Li 2020-02-27 00:02:18 +08:00
parent 90898e700f
commit b8fb9dbb9e
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
1 changed files with 4 additions and 1 deletions

View File

@ -95,9 +95,12 @@ 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.pipe(res)
stream.on('end', () => {
stream.close()
fs.unlinkSync(pdfPath)
})
stream.pipe(res)
})
}
const outputFormats = {