fix export of bad pads and also limit import to files

pull/2525/head
John McLear 2015-02-21 12:33:30 +00:00
parent abb9b6d833
commit d5bec1701e
2 changed files with 17 additions and 2 deletions

View File

@ -48,7 +48,7 @@ exports.getPadRaw = function(padId, callback){
// Get the author info
db.get("globalAuthor:"+authorId, function(e, authorEntry){
authorEntry.padIDs = padId;
if(authorEntry && authorEntry.padIDs) authorEntry.padIDs = padId;
if(!e) data["globalAuthor:"+authorId] = authorEntry;
});

View File

@ -21,9 +21,22 @@ var db = require("../db/DB").db;
exports.setPadRaw = function(padId, records, callback){
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){
var value = records[key]
if(!value){
cb(); // null values are bad.
}
// Author data
if(value.padIDs){
// rewrite author pad ids
@ -34,7 +47,9 @@ exports.setPadRaw = function(padId, records, callback){
db.get(key, function(err, author){
if(author){
// Yes, add the padID to the author..
author.padIDs.push(padId);
if( Object.prototype.toString.call(author) === '[object Array]'){
author.padIDs.push(padId);
}
value = author;
}else{
// No, create a new array with the author info in