Check to ensure image format conversion was successful

This commit is contained in:
Joseph Rautenbach 2019-05-23 11:46:43 +02:00
parent 0cce3abc24
commit 05d3f49621

5
app.js
View File

@ -110,6 +110,8 @@ app.post('/convert', function (req, res) {
} }
shell.exec(finalSvgToImageCMD); shell.exec(finalSvgToImageCMD);
// Ensure conversion was successful; eg. fails if `svgexport` or `imagemin` is not installed
if (fs.existsSync(`${tempDirRoot}${id}/equation.${fileFormat}`)) {
// Compress the resultant image // Compress the resultant image
var finalImageMinCMD = imageMinCMD.replace('IN_FILE_NAME', `${tempDirRoot}${id}/equation.${fileFormat}`); var finalImageMinCMD = imageMinCMD.replace('IN_FILE_NAME', `${tempDirRoot}${id}/equation.${fileFormat}`);
finalImageMinCMD = finalImageMinCMD.replace('OUT_FILE_NAME', `${tempDirRoot}${id}/equation_compressed.${fileFormat}`); finalImageMinCMD = finalImageMinCMD.replace('OUT_FILE_NAME', `${tempDirRoot}${id}/equation_compressed.${fileFormat}`);
@ -119,6 +121,9 @@ app.post('/convert', function (req, res) {
shell.cp(`${tempDirRoot}${id}/equation_compressed.${fileFormat}`, `${outputDir}img-${id}.${fileFormat}`); shell.cp(`${tempDirRoot}${id}/equation_compressed.${fileFormat}`, `${outputDir}img-${id}.${fileFormat}`);
result.imageURL = `${httpOutputURL}img-${id}.${fileFormat}`; result.imageURL = `${httpOutputURL}img-${id}.${fileFormat}`;
} else {
result.error = `Error converting SVG file to ${fileFormat.toUpperCase()} image.`;
}
} }
} else { } else {
result.error = 'Error converting LaTeX to image. Please ensure the input is valid.'; result.error = 'Error converting LaTeX to image. Please ensure the input is valid.';