not working and erally confused
This commit is contained in:
parent
1fa2b32854
commit
6fcc7c77f9
|
@ -29,8 +29,8 @@ var ERR = require("async-stacktrace")
|
||||||
, formidable = require('formidable')
|
, formidable = require('formidable')
|
||||||
, os = require("os")
|
, os = require("os")
|
||||||
, importHtml = require("../utils/ImportHtml")
|
, 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
|
//load abiword only if its enabled
|
||||||
if(settings.abiword != null)
|
if(settings.abiword != null)
|
||||||
|
@ -52,7 +52,10 @@ exports.doImport = function(req, res, padId)
|
||||||
|
|
||||||
var srcFile, destFile
|
var srcFile, destFile
|
||||||
, pad
|
, pad
|
||||||
, text;
|
, text
|
||||||
|
, importHandledByPlugin;
|
||||||
|
|
||||||
|
var randNum = Math.floor(Math.random()*0xFFFFFFFF);
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
//save the uploaded file to /tmp
|
//save the uploaded file to /tmp
|
||||||
|
@ -91,29 +94,45 @@ exports.doImport = function(req, res, padId)
|
||||||
else {
|
else {
|
||||||
var oldSrcFile = srcFile;
|
var oldSrcFile = srcFile;
|
||||||
srcFile = path.join(path.dirname(srcFile),path.basename(srcFile, fileEnding)+".txt");
|
srcFile = path.join(path.dirname(srcFile),path.basename(srcFile, fileEnding)+".txt");
|
||||||
|
|
||||||
fs.rename(oldSrcFile, srcFile, callback);
|
fs.rename(oldSrcFile, srcFile, callback);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
function(callback){
|
||||||
//convert file to html
|
|
||||||
function(callback) {
|
|
||||||
var randNum = Math.floor(Math.random()*0xFFFFFFFF);
|
|
||||||
destFile = path.join(tmpDirectory, "eplite_import_" + randNum + ".htm");
|
destFile = path.join(tmpDirectory, "eplite_import_" + randNum + ".htm");
|
||||||
|
|
||||||
if (abiword) {
|
// Logic for allowing external Import Plugins
|
||||||
abiword.convertFile(srcFile, destFile, "htm", function(err) {
|
hooks.aCallAll("import", {srcFile: srcFile, destFile: destFile}, function(err, result){
|
||||||
//catch convert errors
|
if(ERR(err, callback)) return callback();
|
||||||
if(err) {
|
console.log(result);
|
||||||
console.warn("Converting Error:", err);
|
if(result.length > 0){ // This feels hacky and wrong..
|
||||||
return callback("convertFailed");
|
apiLogger.info("Plugin handling import");
|
||||||
} else {
|
importHandledByPlugin = true;
|
||||||
callback();
|
srcFile = "blah.html";
|
||||||
}
|
callback();
|
||||||
});
|
}else{
|
||||||
} else {
|
callback();
|
||||||
// if no abiword only rename
|
}
|
||||||
fs.rename(srcFile, destFile, 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) {
|
function(callback) {
|
||||||
var fileEnding = path.extname(srcFile).toLowerCase();
|
var fileEnding = path.extname(srcFile).toLowerCase();
|
||||||
if (abiword || fileEnding == ".htm" || fileEnding == ".html") {
|
if (abiword || fileEnding == ".htm" || fileEnding == ".html") {
|
||||||
|
console.log("trying", fileEnding, abiword, text)
|
||||||
try{
|
try{
|
||||||
importHtml.setPadHTML(pad, text);
|
importHtml.setPadHTML(pad, text);
|
||||||
}catch(e){
|
}catch(e){
|
||||||
|
|
Loading…
Reference in New Issue