make setPadRaw async; streamline .etherpad file import handling chain
This commit is contained in:
parent
25092fcb90
commit
a896d67e8c
|
@ -113,10 +113,8 @@ exports.doImport = function(req, res, padId)
|
||||||
if(ERR(err, callback)) return callback();
|
if(ERR(err, callback)) return callback();
|
||||||
if(result.length > 0){ // This feels hacky and wrong..
|
if(result.length > 0){ // This feels hacky and wrong..
|
||||||
importHandledByPlugin = true;
|
importHandledByPlugin = true;
|
||||||
callback();
|
|
||||||
}else{
|
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(callback) {
|
function(callback) {
|
||||||
|
@ -145,7 +143,7 @@ exports.doImport = function(req, res, padId)
|
||||||
},
|
},
|
||||||
//convert file to html
|
//convert file to html
|
||||||
function(callback) {
|
function(callback) {
|
||||||
if(!importHandledByPlugin || !directDatabaseAccess){
|
if(!importHandledByPlugin && !directDatabaseAccess){
|
||||||
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");
|
||||||
|
@ -171,28 +169,24 @@ exports.doImport = function(req, res, padId)
|
||||||
},
|
},
|
||||||
|
|
||||||
function(callback) {
|
function(callback) {
|
||||||
if (!abiword){
|
if (!abiword && !directDatabaseAccess){
|
||||||
if(!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;
|
var isAscii = true;
|
||||||
var isAscii = true;
|
// Check if there are only ascii chars in the uploaded file
|
||||||
// Check if there are only ascii chars in the uploaded file
|
for (var i=0, len=buf.length; i<len; i++) {
|
||||||
for (var i=0, len=buf.length; i<len; i++) {
|
if (buf[i] > 240) {
|
||||||
if (buf[i] > 240) {
|
isAscii=false;
|
||||||
isAscii=false;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (isAscii) {
|
}
|
||||||
callback();
|
if (isAscii) {
|
||||||
} else {
|
callback();
|
||||||
callback("uploadFailed");
|
} else {
|
||||||
}
|
callback("uploadFailed");
|
||||||
});
|
}
|
||||||
}else{
|
});
|
||||||
callback();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,20 +21,11 @@ var db = require("../db/DB").db;
|
||||||
exports.setPadRaw = function(padId, records, callback){
|
exports.setPadRaw = function(padId, records, callback){
|
||||||
records = JSON.parse(records);
|
records = JSON.parse(records);
|
||||||
|
|
||||||
// !! HACK !!
|
|
||||||
// If you have a really large pad it will cause a Maximum Range Stack crash
|
|
||||||
// This is a temporary patch for that so things are kept stable.
|
|
||||||
var recordCount = Object.keys(records).length;
|
|
||||||
if(recordCount >= 50000){
|
|
||||||
console.warn("Etherpad file is too large to import.. We need to fix this. See https://github.com/ether/etherpad-lite/issues/2524");
|
|
||||||
return callback("tooLarge", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.eachSeries(Object.keys(records), function(key, cb){
|
async.eachSeries(Object.keys(records), function(key, cb){
|
||||||
var value = records[key]
|
var value = records[key]
|
||||||
|
|
||||||
if(!value){
|
if(!value){
|
||||||
cb(); // null values are bad.
|
return setImmediate(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Author data
|
// Author data
|
||||||
|
@ -76,7 +67,7 @@ exports.setPadRaw = function(padId, records, callback){
|
||||||
// Write the value to the server
|
// Write the value to the server
|
||||||
db.set(newKey, value);
|
db.set(newKey, value);
|
||||||
|
|
||||||
cb();
|
setImmediate(cb);
|
||||||
}, function(){
|
}, function(){
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue