FIX-2864: Add useAbiword flag

This is a fix for the issue - 2864
Which is import failure of PDF after importing a text file
This commit is contained in:
Jainendra Mandavi 2017-07-28 18:28:23 +05:30
parent f9203524a4
commit e4ddb42e11
1 changed files with 9 additions and 5 deletions
src/node/handler

View File

@ -56,10 +56,14 @@ exports.doImport = function(req, res, padId)
, pad , pad
, text , text
, importHandledByPlugin , importHandledByPlugin
, directDatabaseAccess; , directDatabaseAccess
, useAbiword;
var randNum = Math.floor(Math.random()*0xFFFFFFFF); var randNum = Math.floor(Math.random()*0xFFFFFFFF);
// setting flag for whether to use abiword or not
useAbiword = (abiword != null);
async.series([ async.series([
//save the uploaded file to /tmp //save the uploaded file to /tmp
function(callback) { function(callback) {
@ -147,9 +151,9 @@ exports.doImport = function(req, res, padId)
var fileEnding = path.extname(srcFile).toLowerCase(); var fileEnding = path.extname(srcFile).toLowerCase();
var fileIsHTML = (fileEnding === ".html" || fileEnding === ".htm"); var fileIsHTML = (fileEnding === ".html" || fileEnding === ".htm");
var fileIsTXT = (fileEnding === ".txt"); var fileIsTXT = (fileEnding === ".txt");
if (fileIsTXT) abiword = false; // Don't use abiword for text files if (fileIsTXT) useAbiword = false; // Don't use abiword for text files
// See https://github.com/ether/etherpad-lite/issues/2572 // See https://github.com/ether/etherpad-lite/issues/2572
if (abiword && !fileIsHTML) { if (useAbiword && !fileIsHTML) {
abiword.convertFile(srcFile, destFile, "htm", function(err) { abiword.convertFile(srcFile, destFile, "htm", function(err) {
//catch convert errors //catch convert errors
if(err) { if(err) {
@ -169,7 +173,7 @@ exports.doImport = function(req, res, padId)
}, },
function(callback) { function(callback) {
if (!abiword && !directDatabaseAccess){ if (!useAbiword && !directDatabaseAccess){
// Read the file with no encoding for raw buffer access. // Read the file with no encoding for raw buffer access.
fs.readFile(destFile, function(err, buf) { fs.readFile(destFile, function(err, buf) {
if (err) throw err; if (err) throw err;
@ -228,7 +232,7 @@ exports.doImport = function(req, res, padId)
function(callback) { function(callback) {
if(!directDatabaseAccess){ if(!directDatabaseAccess){
var fileEnding = path.extname(srcFile).toLowerCase(); var fileEnding = path.extname(srcFile).toLowerCase();
if (importHandledByPlugin || abiword || fileEnding == ".htm" || fileEnding == ".html") { if (importHandledByPlugin || useAbiword || fileEnding == ".htm" || fileEnding == ".html") {
importHtml.setPadHTML(pad, text, function(e){ importHtml.setPadHTML(pad, text, function(e){
if(e) apiLogger.warn("Error importing, possibly caused by malformed HTML"); if(e) apiLogger.warn("Error importing, possibly caused by malformed HTML");
}); });