Fix server crash on PDF creation

`markdown-pdf` seems to fail to provide the PDFs on tmpfs. This leads
crashing codimd which expects the file to be there. This patch should
add some proper error handling when expectation and reality don't fit
together.

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
This commit is contained in:
Sheogorath 2018-09-24 17:55:03 +02:00
parent 32afa14375
commit 6fdb9eea46
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
1 changed files with 4 additions and 0 deletions

View File

@ -341,6 +341,10 @@ function actionPDF (req, res, note) {
var path = config.tmpPath + '/' + Date.now() + '.pdf'
content = content.replace(/\]\(\//g, '](' + url + '/')
markdownpdf().from.string(content).to(path, function () {
if (!fs.existsSync(path)) {
logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + path)
return response.errorInternalError(res)
}
var stream = fs.createReadStream(path)
var filename = title
// Be careful of special characters