mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
import/export: conversion to Promises/async
NB1: needs additional review and testing - no abiword available on my test bed NB2: in ImportHandler.js, directly delete the file, and handle the eventual error later: checking before for existence is prone to race conditions, and does not handle any errors anyway.
This commit is contained in:
parent
5192a0c498
commit
62345ac8f7
8 changed files with 379 additions and 570 deletions
|
@ -15,59 +15,48 @@
|
|||
*/
|
||||
|
||||
|
||||
var async = require("async");
|
||||
var db = require("../db/DB").db;
|
||||
var ERR = require("async-stacktrace");
|
||||
const thenify = require("thenify").withCallback;
|
||||
let db = require("../db/DB");
|
||||
|
||||
exports.getPadRaw = thenify(function(padId, callback){
|
||||
async.waterfall([
|
||||
function(cb){
|
||||
db.get("pad:"+padId, cb);
|
||||
},
|
||||
function(padcontent,cb){
|
||||
var records = ["pad:"+padId];
|
||||
for (var i = 0; i <= padcontent.head; i++) {
|
||||
records.push("pad:"+padId+":revs:" + i);
|
||||
}
|
||||
exports.getPadRaw = async function(padId) {
|
||||
|
||||
for (var i = 0; i <= padcontent.chatHead; i++) {
|
||||
records.push("pad:"+padId+":chat:" + i);
|
||||
}
|
||||
let padKey = "pad:" + padId;
|
||||
let padcontent = await db.get(padKey);
|
||||
|
||||
var data = {};
|
||||
|
||||
async.forEachSeries(Object.keys(records), function(key, r){
|
||||
|
||||
// For each piece of info about a pad.
|
||||
db.get(records[key], function(err, entry){
|
||||
data[records[key]] = entry;
|
||||
|
||||
// Get the Pad Authors
|
||||
if(entry.pool && entry.pool.numToAttrib){
|
||||
var authors = entry.pool.numToAttrib;
|
||||
async.forEachSeries(Object.keys(authors), function(k, c){
|
||||
if(authors[k][0] === "author"){
|
||||
var authorId = authors[k][1];
|
||||
|
||||
// Get the author info
|
||||
db.get("globalAuthor:"+authorId, function(e, authorEntry){
|
||||
if(authorEntry && authorEntry.padIDs) authorEntry.padIDs = padId;
|
||||
if(!e) data["globalAuthor:"+authorId] = authorEntry;
|
||||
});
|
||||
|
||||
}
|
||||
// console.log("authorsK", authors[k]);
|
||||
c(null);
|
||||
});
|
||||
}
|
||||
r(null); // callback;
|
||||
});
|
||||
}, function(err){
|
||||
cb(err, data);
|
||||
})
|
||||
let records = [ padKey ];
|
||||
for (let i = 0; i <= padcontent.head; i++) {
|
||||
records.push(padKey + ":revs:" + i);
|
||||
}
|
||||
], function(err, data){
|
||||
callback(null, data);
|
||||
});
|
||||
});
|
||||
|
||||
for (let i = 0; i <= padcontent.chatHead; i++) {
|
||||
records.push(padKey + ":chat:" + i);
|
||||
}
|
||||
|
||||
let data = {};
|
||||
for (let key of records) {
|
||||
|
||||
// For each piece of info about a pad.
|
||||
let entry = data[key] = await db.get(key);
|
||||
|
||||
// Get the Pad Authors
|
||||
if (entry.pool && entry.pool.numToAttrib) {
|
||||
let authors = entry.pool.numToAttrib;
|
||||
|
||||
for (let k of Object.keys(authors)) {
|
||||
if (authors[k][0] === "author") {
|
||||
let authorId = authors[k][1];
|
||||
|
||||
// Get the author info
|
||||
let authorEntry = await db.get("globalAuthor:" + authorId);
|
||||
if (authorEntry) {
|
||||
data["globalAuthor:" + authorId] = authorEntry;
|
||||
if (authorEntry.padIDs) {
|
||||
authorEntry.padIDs = padId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue