mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
db/PadManager.js: more conversion to Promises/async
This commit is contained in:
parent
8108964472
commit
bbe4a5f756
1 changed files with 29 additions and 32 deletions
|
@ -50,46 +50,43 @@ var globalPads = {
|
||||||
*
|
*
|
||||||
* Updated without db access as new pads are created/old ones removed.
|
* Updated without db access as new pads are created/old ones removed.
|
||||||
*/
|
*/
|
||||||
var padList = {
|
let padList = {
|
||||||
list: [],
|
list: [],
|
||||||
sorted : false,
|
sorted : false,
|
||||||
initiated: false,
|
initiated: false,
|
||||||
init: thenify(function(cb) {
|
init: async function() {
|
||||||
db.findKeys("pad:*", "*:*:*", function(err, dbData) {
|
let dbData = await db.findKeys("pad:*", "*:*:*");
|
||||||
if (ERR(err, cb)) return;
|
|
||||||
|
|
||||||
if (dbData != null) {
|
if (dbData != null) {
|
||||||
padList.initiated = true
|
this.initiated = true;
|
||||||
dbData.forEach(function(val) {
|
|
||||||
padList.addPad(val.replace(/pad:/,""),false);
|
|
||||||
});
|
|
||||||
|
|
||||||
cb && cb();
|
for (let val of dbData) {
|
||||||
|
this.addPad(val.replace(/pad:/,""), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}),
|
},
|
||||||
load: thenify(function(cb) {
|
load: async function() {
|
||||||
if (this.initiated) {
|
if (!this.initiated) {
|
||||||
cb && cb();
|
return this.init();
|
||||||
} else {
|
|
||||||
this.init(cb);
|
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Returns all pads in alphabetical order as array.
|
* Returns all pads in alphabetical order as array.
|
||||||
*/
|
*/
|
||||||
getPads: thenify(function(cb) {
|
getPads: async function() {
|
||||||
this.load(function() {
|
await this.load();
|
||||||
if (!padList.sorted) {
|
|
||||||
padList.list = padList.list.sort();
|
if (!this.sorted) {
|
||||||
padList.sorted = true;
|
this.list.sort();
|
||||||
|
this.sorted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cb && cb(padList.list);
|
return this.list;
|
||||||
})
|
},
|
||||||
}),
|
|
||||||
addPad: function(name) {
|
addPad: function(name) {
|
||||||
if (!this.initiated) return;
|
if (!this.initiated) return;
|
||||||
|
|
||||||
|
@ -171,12 +168,12 @@ exports.getPad = thenify(function(id, text, callback)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.listAllPads = thenify(function(cb)
|
exports.listAllPads = async function()
|
||||||
{
|
{
|
||||||
padList.getPads(function(list) {
|
let padIDs = await padList.getPads();
|
||||||
cb && cb(null, {padIDs: list});
|
|
||||||
});
|
return { padIDs };
|
||||||
});
|
}
|
||||||
|
|
||||||
// checks if a pad exists
|
// checks if a pad exists
|
||||||
exports.doesPadExist = thenify(function(padId, callback)
|
exports.doesPadExist = thenify(function(padId, callback)
|
||||||
|
|
Loading…
Reference in a new issue