From 6fcc7c77f901bac7cc39b5e10cfc4a199dc8245a Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 27 Nov 2013 00:23:11 +0000 Subject: [PATCH 1/3] not working and erally confused --- src/node/handler/ImportHandler.js | 62 ++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 98909354c..be119e099 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -29,8 +29,8 @@ var ERR = require("async-stacktrace") , formidable = require('formidable') , os = require("os") , importHtml = require("../utils/ImportHtml") - , log4js = require('log4js'); - + , log4js = require("log4js") + , hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js"); //load abiword only if its enabled if(settings.abiword != null) @@ -52,7 +52,10 @@ exports.doImport = function(req, res, padId) var srcFile, destFile , pad - , text; + , text + , importHandledByPlugin; + + var randNum = Math.floor(Math.random()*0xFFFFFFFF); async.series([ //save the uploaded file to /tmp @@ -91,29 +94,45 @@ exports.doImport = function(req, res, padId) else { var oldSrcFile = srcFile; srcFile = path.join(path.dirname(srcFile),path.basename(srcFile, fileEnding)+".txt"); - fs.rename(oldSrcFile, srcFile, callback); } }, - - //convert file to html - function(callback) { - var randNum = Math.floor(Math.random()*0xFFFFFFFF); + function(callback){ destFile = path.join(tmpDirectory, "eplite_import_" + randNum + ".htm"); - if (abiword) { - abiword.convertFile(srcFile, destFile, "htm", function(err) { - //catch convert errors - if(err) { - console.warn("Converting Error:", err); - return callback("convertFailed"); - } else { - callback(); - } - }); - } else { - // if no abiword only rename - fs.rename(srcFile, destFile, callback); + // Logic for allowing external Import Plugins + hooks.aCallAll("import", {srcFile: srcFile, destFile: destFile}, function(err, result){ + if(ERR(err, callback)) return callback(); +console.log(result); + if(result.length > 0){ // This feels hacky and wrong.. + apiLogger.info("Plugin handling import"); + importHandledByPlugin = true; + srcFile = "blah.html"; + callback(); + }else{ + callback(); + } + }); + }, + //convert file to html + function(callback) { + if(!importHandledByPlugin){ + if (abiword) { + abiword.convertFile(srcFile, destFile, "htm", function(err) { + //catch convert errors + if(err) { + console.warn("Converting Error:", err); + return callback("convertFailed"); + } else { + callback(); + } + }); + } else { + // if no abiword only rename + fs.rename(srcFile, destFile, callback); + } + }else{ + callback(); } }, @@ -173,6 +192,7 @@ exports.doImport = function(req, res, padId) function(callback) { var fileEnding = path.extname(srcFile).toLowerCase(); if (abiword || fileEnding == ".htm" || fileEnding == ".html") { +console.log("trying", fileEnding, abiword, text) try{ importHtml.setPadHTML(pad, text); }catch(e){ From 271dd663bf386f9fdcd6a5a8a835414054e9815b Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 28 Nov 2013 17:22:34 +0000 Subject: [PATCH 2/3] foo --- src/node/handler/ImportHandler.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index be119e099..3e00be77b 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -105,9 +105,8 @@ exports.doImport = function(req, res, padId) if(ERR(err, callback)) return callback(); console.log(result); if(result.length > 0){ // This feels hacky and wrong.. - apiLogger.info("Plugin handling import"); + console.log("Plugin handling import"); importHandledByPlugin = true; - srcFile = "blah.html"; callback(); }else{ callback(); From 3180b96213ab0e8f18be5370899bb515e0afcb72 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 9 Dec 2013 18:13:07 +0000 Subject: [PATCH 3/3] Remove console logs --- src/node/handler/ImportHandler.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index 3e00be77b..c751f8f98 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -103,9 +103,7 @@ exports.doImport = function(req, res, padId) // Logic for allowing external Import Plugins hooks.aCallAll("import", {srcFile: srcFile, destFile: destFile}, function(err, result){ if(ERR(err, callback)) return callback(); -console.log(result); if(result.length > 0){ // This feels hacky and wrong.. - console.log("Plugin handling import"); importHandledByPlugin = true; callback(); }else{ @@ -191,7 +189,6 @@ console.log(result); function(callback) { var fileEnding = path.extname(srcFile).toLowerCase(); if (abiword || fileEnding == ".htm" || fileEnding == ".html") { -console.log("trying", fileEnding, abiword, text) try{ importHtml.setPadHTML(pad, text); }catch(e){