diff --git a/src/node/utils/LibreOffice.js b/src/node/utils/LibreOffice.js index d72b93249..e2c6430b0 100644 --- a/src/node/utils/LibreOffice.js +++ b/src/node/utils/LibreOffice.js @@ -38,6 +38,9 @@ var libreOfficeLogger = log4js.getLogger('LibreOffice'); * @param {Function} callback Standard callback function */ exports.convertFile = function(srcFile, destFile, type, callback) { + // Used for the moving of the file, not the conversion + var fileExtension = type; + // soffice can't convert from html to doc directly (verified with LO 5 and 6) // we need to convert to odt first, then to doc // to avoid `Error: no export filter for /tmp/xxxx.doc` error @@ -47,11 +50,11 @@ exports.convertFile = function(srcFile, destFile, type, callback) { "destFile": destFile.replace(/\.doc$/, '.odt'), "type": 'odt', "callback": function () { - queue.push({"srcFile": srcFile.replace(/\.html$/, '.odt'), "destFile": destFile, "type": type, "callback": callback}); + queue.push({"srcFile": srcFile.replace(/\.html$/, '.odt'), "destFile": destFile, "type": type, "callback": callback, "fileExtension": fileExtension }); } }); } else { - queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback}); + queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback, "fileExtension": fileExtension}); } }; @@ -102,7 +105,7 @@ function doConvertTask(task, callback) { // Move the converted file to the correct place function(callback) { var filename = path.basename(task.srcFile); - var sourceFilename = filename.substr(0, filename.lastIndexOf('.')) + '.' + task.type; + var sourceFilename = filename.substr(0, filename.lastIndexOf('.')) + '.' + task.fileExtension; var sourcePath = path.join(tmpDir, sourceFilename); libreOfficeLogger.debug(`Renaming ${sourcePath} to ${task.destFile}`); fs.rename(sourcePath, task.destFile, callback);