diff --git a/node/Abiword.js b/node/Abiword.js index 4e70d3fbd..dd9658bc3 100644 --- a/node/Abiword.js +++ b/node/Abiword.js @@ -29,10 +29,10 @@ var queue = async.queue(doConvertTask, 1); //spawn the abiword process var abiword = spawn(settings.abiword, ["--plugin", "AbiCommand"]); -//output error messages to stderr +//append error messages to the buffer abiword.stderr.on('data', function (data) { - console.error("Abiword: " + data); + stdoutBuffer += data.toString(); }); //throw exceptions if abiword is dieing @@ -57,8 +57,7 @@ function onAbiwordStdout(data) if(stdoutBuffer.search("AbiWord:>") != -1) { //filter the feedback message - var lines = stdoutBuffer.split("\n"); - var err = lines [1] == "OK" ? null : lines[1]; + var err = stdoutBuffer.search("OK") != -1 ? null : stdoutBuffer; //reset the buffer stdoutBuffer = ""; diff --git a/node/ImportHandler.js b/node/ImportHandler.js index c7e294831..f8cebb6d1 100644 --- a/node/ImportHandler.js +++ b/node/ImportHandler.js @@ -58,6 +58,38 @@ exports.doImport = function(req, res, padId) }); }, + //ensure this is a file ending we know, else we change the file ending to .txt + //this allows us to accept source code files like .c or .java + function(callback) + { + var fileEnding = srcFile.split(".")[1]; + var knownFileEndings = ["txt", "doc", "docx", "pdf", "odt", "html", "htm"]; + + //find out if this is a known file ending + var fileEndingKnown = false; + for(var i in knownFileEndings) + { + if(fileEnding == knownFileEndings[i]) + { + fileEndingKnown = true; + } + } + + //if the file ending is known, continue as normal + if(fileEndingKnown) + { + callback(); + } + //we need to rename this file with a .txt ending + else + { + var oldSrcFile = srcFile; + srcFile = srcFile.split(".")[0] + ".txt"; + + fs.rename(oldSrcFile, srcFile, callback); + } + }, + //convert file to text function(callback) { @@ -109,9 +141,9 @@ exports.doImport = function(req, res, padId) } ], function(err) { + if(err) throw err; + //close the connection res.send("ok"); - - if(err) throw err; }); } diff --git a/node/minify.js b/node/minify.js index 54fe18483..e438de229 100644 --- a/node/minify.js +++ b/node/minify.js @@ -228,24 +228,34 @@ exports.padJS = function(req, res) res.sendfile(pathStr, { maxAge: server.maxAge }); }) } - //minifying is disabled, so load the files with jquery + //minifying is disabled, so put the files together in one file else { - res.write("function loadjsfile(filename){\n"+ - "var fileref=document.createElement('script');\n"+ - "fileref.setAttribute('type','text/javascript');\n"+ - "var path = 'static/js/' + filename;\n"+ - "fileref.setAttribute('src', path);\n" + - "document.getElementsByTagName('head')[0].appendChild(fileref);\n" + - "}\n"); + var fileValues = {}; - for(var i in jsFiles) + //read all js files + async.forEach(jsFiles, function (item, callback) { - console.log(jsFiles[i]); - res.write("loadjsfile('"+ jsFiles[i] + "');\n"); - } - - res.end(); + fs.readFile("../static/js/" + item, "utf-8", function(err, data) + { + fileValues[item] = data; + callback(err); + }); + }, + //send all files together + function(err) + { + if(err) throw err; + + for(var i=0;i Etherpad Lite - - - +