mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
Merge branch 'master' of .git into api
This commit is contained in:
commit
1a824bd130
12 changed files with 196 additions and 107 deletions
|
@ -23,11 +23,20 @@ var padManager = require("../db/PadManager");
|
|||
var async = require("async");
|
||||
var fs = require("fs");
|
||||
var settings = require('../utils/Settings');
|
||||
var os = require('os');
|
||||
|
||||
//load abiword only if its enabled
|
||||
if(settings.abiword != null)
|
||||
var abiword = require("../utils/Abiword");
|
||||
|
||||
var tempDirectory = "/tmp";
|
||||
|
||||
//tempDirectory changes if the operating system is windows
|
||||
if(os.type().indexOf("Windows") > -1)
|
||||
{
|
||||
tempDirectory = "c:\\Temp";
|
||||
}
|
||||
|
||||
/**
|
||||
* do a requested export
|
||||
*/
|
||||
|
@ -52,7 +61,7 @@ exports.doExport = function(req, res, padId, type)
|
|||
var html;
|
||||
var randNum;
|
||||
var srcFile, destFile;
|
||||
|
||||
|
||||
async.series([
|
||||
//render the html document
|
||||
function(callback)
|
||||
|
@ -76,7 +85,7 @@ exports.doExport = function(req, res, padId, type)
|
|||
else
|
||||
{
|
||||
randNum = Math.floor(Math.random()*new Date().getTime());
|
||||
srcFile = "/tmp/eplite_export_" + randNum + ".html";
|
||||
srcFile = tempDirectory + "/eplite_export_" + randNum + ".html";
|
||||
fs.writeFile(srcFile, html, callback);
|
||||
}
|
||||
},
|
||||
|
@ -86,7 +95,7 @@ exports.doExport = function(req, res, padId, type)
|
|||
//ensure html can be collected by the garbage collector
|
||||
html = null;
|
||||
|
||||
destFile = "/tmp/eplite_export_" + randNum + "." + type;
|
||||
destFile = tempDirectory + "/eplite_export_" + randNum + "." + type;
|
||||
abiword.convertFile(srcFile, destFile, type, callback);
|
||||
},
|
||||
//send the file
|
||||
|
@ -104,7 +113,11 @@ exports.doExport = function(req, res, padId, type)
|
|||
},
|
||||
function(callback)
|
||||
{
|
||||
fs.unlink(destFile, callback);
|
||||
//100ms delay to accomidate for slow windows fs
|
||||
setTimeout(function()
|
||||
{
|
||||
fs.unlink(destFile, callback);
|
||||
}, 100);
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
|
|
@ -24,10 +24,19 @@ var async = require("async");
|
|||
var fs = require("fs");
|
||||
var settings = require('../utils/Settings');
|
||||
var formidable = require('formidable');
|
||||
var os = require("os");
|
||||
|
||||
//load abiword only if its enabled
|
||||
if(settings.abiword != null)
|
||||
var abiword = require("../utils/Abiword");
|
||||
|
||||
var tempDirectory = "/tmp/";
|
||||
|
||||
//tempDirectory changes if the operating system is windows
|
||||
if(os.type().indexOf("Windows") > -1)
|
||||
{
|
||||
tempDirectory = "c:\\Temp\\";
|
||||
}
|
||||
|
||||
/**
|
||||
* do a requested import
|
||||
|
@ -48,6 +57,7 @@ exports.doImport = function(req, res, padId)
|
|||
{
|
||||
var form = new formidable.IncomingForm();
|
||||
form.keepExtensions = true;
|
||||
form.uploadDir = tempDirectory;
|
||||
|
||||
form.parse(req, function(err, fields, files)
|
||||
{
|
||||
|
@ -94,7 +104,7 @@ exports.doImport = function(req, res, padId)
|
|||
function(callback)
|
||||
{
|
||||
var randNum = Math.floor(Math.random()*new Date().getTime());
|
||||
destFile = "/tmp/eplite_import_" + randNum + ".txt";
|
||||
destFile = tempDirectory + "eplite_import_" + randNum + ".txt";
|
||||
abiword.convertFile(srcFile, destFile, "txt", callback);
|
||||
},
|
||||
|
||||
|
@ -114,7 +124,13 @@ exports.doImport = function(req, res, padId)
|
|||
fs.readFile(destFile, "utf8", function(err, _text)
|
||||
{
|
||||
text = _text;
|
||||
callback(err);
|
||||
|
||||
//node on windows has a delay on releasing of the file lock.
|
||||
//We add a 100ms delay to work around this
|
||||
setTimeout(function()
|
||||
{
|
||||
callback(err);
|
||||
}, 100);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -22,71 +22,121 @@ var util = require('util');
|
|||
var spawn = require('child_process').spawn;
|
||||
var async = require("async");
|
||||
var settings = require("./Settings");
|
||||
var os = require('os');
|
||||
|
||||
//Queue with the converts we have to do
|
||||
var queue = async.queue(doConvertTask, 1);
|
||||
|
||||
//spawn the abiword process
|
||||
var abiword = spawn(settings.abiword, ["--plugin", "AbiCommand"]);
|
||||
|
||||
//append error messages to the buffer
|
||||
abiword.stderr.on('data', function (data)
|
||||
//on windows we have to spawn a process for each convertion, cause the plugin abicommand doesn't exist on this platform
|
||||
if(os.type().indexOf("Windows") > -1)
|
||||
{
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
var stdoutBuffer = "";
|
||||
|
||||
//throw exceptions if abiword is dieing
|
||||
abiword.on('exit', function (code)
|
||||
{
|
||||
throw "Abiword died with exit code " + code;
|
||||
});
|
||||
|
||||
//delegate the processing of stdout to a other function
|
||||
abiword.stdout.on('data',onAbiwordStdout);
|
||||
|
||||
var stdoutCallback = null;
|
||||
var stdoutBuffer = "";
|
||||
var firstPrompt = true;
|
||||
|
||||
function onAbiwordStdout(data)
|
||||
{
|
||||
//add data to buffer
|
||||
stdoutBuffer+=data.toString();
|
||||
|
||||
//we're searching for the prompt, cause this means everything we need is in the buffer
|
||||
if(stdoutBuffer.search("AbiWord:>") != -1)
|
||||
function doConvertTask(task, callback)
|
||||
{
|
||||
//filter the feedback message
|
||||
var err = stdoutBuffer.search("OK") != -1 ? null : stdoutBuffer;
|
||||
//span an abiword process to perform the conversion
|
||||
var abiword = spawn(settings.abiword, ["--to=" + task.destFile, task.srcFile]);
|
||||
|
||||
//reset the buffer
|
||||
stdoutBuffer = "";
|
||||
|
||||
//call the callback with the error message
|
||||
//skip the first prompt
|
||||
if(stdoutCallback != null && !firstPrompt)
|
||||
//delegate the processing of stdout to another function
|
||||
abiword.stdout.on('data', function (data)
|
||||
{
|
||||
stdoutCallback(err);
|
||||
stdoutCallback = null;
|
||||
}
|
||||
|
||||
firstPrompt = false;
|
||||
}
|
||||
}
|
||||
//add data to buffer
|
||||
stdoutBuffer+=data.toString();
|
||||
});
|
||||
|
||||
function doConvertTask(task, callback)
|
||||
{
|
||||
abiword.stdin.write("convert " + task.srcFile + " " + task.destFile + " " + task.type + "\n");
|
||||
//append error messages to the buffer
|
||||
abiword.stderr.on('data', function (data)
|
||||
{
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
//throw exceptions if abiword is dieing
|
||||
abiword.on('exit', function (code)
|
||||
{
|
||||
if(code != 0) {
|
||||
throw "Abiword died with exit code " + code;
|
||||
}
|
||||
|
||||
if(stdoutBuffer != "")
|
||||
{
|
||||
console.log(stdoutBuffer);
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
//create a callback that calls the task callback and the caller callback
|
||||
stdoutCallback = function (err)
|
||||
exports.convertFile = function(srcFile, destFile, type, callback)
|
||||
{
|
||||
callback();
|
||||
task.callback(err);
|
||||
doConvertTask({"srcFile": srcFile, "destFile": destFile, "type": type}, callback);
|
||||
};
|
||||
}
|
||||
|
||||
exports.convertFile = function(srcFile, destFile, type, callback)
|
||||
//on unix operating systems, we can start abiword with abicommand and communicate with it via stdin/stdout
|
||||
//thats much faster, about factor 10
|
||||
else
|
||||
{
|
||||
queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback});
|
||||
};
|
||||
//Queue with the converts we have to do
|
||||
var queue = async.queue(doConvertTask, 1);
|
||||
|
||||
//spawn the abiword process
|
||||
var abiword = spawn(settings.abiword, ["--plugin", "AbiCommand"]);
|
||||
|
||||
//append error messages to the buffer
|
||||
abiword.stderr.on('data', function (data)
|
||||
{
|
||||
stdoutBuffer += data.toString();
|
||||
});
|
||||
|
||||
//throw exceptions if abiword is dieing
|
||||
abiword.on('exit', function (code)
|
||||
{
|
||||
throw "Abiword died with exit code " + code;
|
||||
});
|
||||
|
||||
//delegate the processing of stdout to a other function
|
||||
abiword.stdout.on('data',onAbiwordStdout);
|
||||
|
||||
var stdoutCallback = null;
|
||||
var stdoutBuffer = "";
|
||||
var firstPrompt = true;
|
||||
|
||||
function onAbiwordStdout(data)
|
||||
{
|
||||
//add data to buffer
|
||||
stdoutBuffer+=data.toString();
|
||||
|
||||
//we're searching for the prompt, cause this means everything we need is in the buffer
|
||||
if(stdoutBuffer.search("AbiWord:>") != -1)
|
||||
{
|
||||
//filter the feedback message
|
||||
var err = stdoutBuffer.search("OK") != -1 ? null : stdoutBuffer;
|
||||
|
||||
//reset the buffer
|
||||
stdoutBuffer = "";
|
||||
|
||||
//call the callback with the error message
|
||||
//skip the first prompt
|
||||
if(stdoutCallback != null && !firstPrompt)
|
||||
{
|
||||
stdoutCallback(err);
|
||||
stdoutCallback = null;
|
||||
}
|
||||
|
||||
firstPrompt = false;
|
||||
}
|
||||
}
|
||||
|
||||
function doConvertTask(task, callback)
|
||||
{
|
||||
abiword.stdin.write("convert " + task.srcFile + " " + task.destFile + " " + task.type + "\n");
|
||||
|
||||
//create a callback that calls the task callback and the caller callback
|
||||
stdoutCallback = function (err)
|
||||
{
|
||||
callback();
|
||||
task.callback(err);
|
||||
};
|
||||
}
|
||||
|
||||
exports.convertFile = function(srcFile, destFile, type, callback)
|
||||
{
|
||||
queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ var path = require('path');
|
|||
var Buffer = require('buffer').Buffer;
|
||||
var gzip = require('gzip');
|
||||
var server = require('../server');
|
||||
var os = require('os');
|
||||
|
||||
var padJS = ["jquery.min.js", "pad_utils.js", "plugins.js", "undo-xpopup.js", "json2.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "ace.js", "collab_client.js", "pad_userlist.js", "pad_impexp.js", "pad_savedrevs.js", "pad_connectionstatus.js", "pad2.js", "jquery-ui.js", "chat.js"];
|
||||
|
||||
|
@ -222,11 +223,20 @@ exports.minifyJS = function(req, res, jsFilename)
|
|||
//write the results compressed in a file
|
||||
function(callback)
|
||||
{
|
||||
gzip(result, 9, function(err, compressedResult){
|
||||
if(err) {callback(err); return}
|
||||
|
||||
fs.writeFile("../var/minified_" + jsFilename + ".gz", compressedResult, callback);
|
||||
});
|
||||
//spawn a gzip process if we're on a unix system
|
||||
if(os.type().indexOf("Windows") == -1)
|
||||
{
|
||||
gzip(result, 9, function(err, compressedResult){
|
||||
if(err) {callback(err); return}
|
||||
|
||||
fs.writeFile("../var/minified_" + jsFilename + ".gz", compressedResult, callback);
|
||||
});
|
||||
}
|
||||
//skip this step on windows
|
||||
else
|
||||
{
|
||||
callback();
|
||||
}
|
||||
}
|
||||
],callback);
|
||||
}
|
||||
|
@ -238,7 +248,7 @@ exports.minifyJS = function(req, res, jsFilename)
|
|||
var gzipSupport = req.header('Accept-Encoding', '').indexOf('gzip') != -1;
|
||||
|
||||
var pathStr;
|
||||
if(gzipSupport)
|
||||
if(gzipSupport && os.type().indexOf("Windows") == -1)
|
||||
{
|
||||
pathStr = path.normalize(__dirname + "/../../var/minified_" + jsFilename + ".gz");
|
||||
res.header('Content-Encoding', 'gzip');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue