mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
start using "thenify" to support callback and promises
PadManager.sanitizePadId() can't use thenify: single arg callback
This commit is contained in:
parent
40c45077ef
commit
17fe32ec0c
9 changed files with 170 additions and 168 deletions
|
@ -33,6 +33,7 @@ var exportTxt = require("../utils/ExportTxt");
|
||||||
var importHtml = require("../utils/ImportHtml");
|
var importHtml = require("../utils/ImportHtml");
|
||||||
var cleanText = require("./Pad").cleanText;
|
var cleanText = require("./Pad").cleanText;
|
||||||
var PadDiff = require("../utils/padDiff");
|
var PadDiff = require("../utils/padDiff");
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
/**********************/
|
/**********************/
|
||||||
/**GROUP FUNCTIONS*****/
|
/**GROUP FUNCTIONS*****/
|
||||||
|
@ -103,14 +104,14 @@ Example returns:
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
exports.getAttributePool = function(padID, callback)
|
exports.getAttributePool = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
|
||||||
callback(null, {pool: pad.pool});
|
callback(null, {pool: pad.pool});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getRevisionChangeset (padID, [rev])
|
getRevisionChangeset (padID, [rev])
|
||||||
|
@ -125,7 +126,7 @@ Example returns:
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
exports.getRevisionChangeset = function(padID, rev, callback)
|
exports.getRevisionChangeset = thenify(function(padID, rev, callback)
|
||||||
{
|
{
|
||||||
// check if rev is a number
|
// check if rev is a number
|
||||||
if (rev !== undefined && typeof rev !== "number") {
|
if (rev !== undefined && typeof rev !== "number") {
|
||||||
|
@ -179,7 +180,7 @@ exports.getRevisionChangeset = function(padID, rev, callback)
|
||||||
callback(null, changeset);
|
callback(null, changeset);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getText(padID, [rev]) returns the text of a pad
|
getText(padID, [rev]) returns the text of a pad
|
||||||
|
@ -189,7 +190,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {text:"Welcome Text"}}
|
{code: 0, message:"ok", data: {text:"Welcome Text"}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getText = function(padID, rev, callback)
|
exports.getText = thenify(function(padID, rev, callback)
|
||||||
{
|
{
|
||||||
// check if rev is a number
|
// check if rev is a number
|
||||||
if (rev !== undefined && typeof rev !== "number") {
|
if (rev !== undefined && typeof rev !== "number") {
|
||||||
|
@ -242,7 +243,7 @@ exports.getText = function(padID, rev, callback)
|
||||||
var padText = exportTxt.getTXTFromAtext(pad, pad.atext);
|
var padText = exportTxt.getTXTFromAtext(pad, pad.atext);
|
||||||
callback(null, {"text": padText});
|
callback(null, {"text": padText});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
setText(padID, text) sets the text of a pad
|
setText(padID, text) sets the text of a pad
|
||||||
|
@ -253,7 +254,7 @@ Example returns:
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
{code: 1, message:"text too long", data: null}
|
{code: 1, message:"text too long", data: null}
|
||||||
*/
|
*/
|
||||||
exports.setText = function(padID, text, callback)
|
exports.setText = thenify(function(padID, text, callback)
|
||||||
{
|
{
|
||||||
// text is required
|
// text is required
|
||||||
if (typeof text !== "string") {
|
if (typeof text !== "string") {
|
||||||
|
@ -271,7 +272,7 @@ exports.setText = function(padID, text, callback)
|
||||||
// update the clients on the pad
|
// update the clients on the pad
|
||||||
padMessageHandler.updatePadClients(pad, callback);
|
padMessageHandler.updatePadClients(pad, callback);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
appendText(padID, text) appends text to a pad
|
appendText(padID, text) appends text to a pad
|
||||||
|
@ -282,7 +283,7 @@ Example returns:
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
{code: 1, message:"text too long", data: null}
|
{code: 1, message:"text too long", data: null}
|
||||||
*/
|
*/
|
||||||
exports.appendText = function(padID, text, callback)
|
exports.appendText = thenify(function(padID, text, callback)
|
||||||
{
|
{
|
||||||
// text is required
|
// text is required
|
||||||
if (typeof text !== "string") {
|
if (typeof text !== "string") {
|
||||||
|
@ -299,7 +300,7 @@ exports.appendText = function(padID, text, callback)
|
||||||
// update the clients on the pad
|
// update the clients on the pad
|
||||||
padMessageHandler.updatePadClients(pad, callback);
|
padMessageHandler.updatePadClients(pad, callback);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getHTML(padID, [rev]) returns the html of a pad
|
getHTML(padID, [rev]) returns the html of a pad
|
||||||
|
@ -309,7 +310,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {text:"Welcome <strong>Text</strong>"}}
|
{code: 0, message:"ok", data: {text:"Welcome <strong>Text</strong>"}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getHTML = function(padID, rev, callback)
|
exports.getHTML = thenify(function(padID, rev, callback)
|
||||||
{
|
{
|
||||||
if (rev !== undefined && typeof rev !== "number") {
|
if (rev !== undefined && typeof rev !== "number") {
|
||||||
if (isNaN(parseInt(rev))) {
|
if (isNaN(parseInt(rev))) {
|
||||||
|
@ -362,7 +363,7 @@ exports.getHTML = function(padID, rev, callback)
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
setHTML(padID, html) sets the text of a pad based on HTML
|
setHTML(padID, html) sets the text of a pad based on HTML
|
||||||
|
@ -372,7 +373,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.setHTML = function(padID, html, callback)
|
exports.setHTML = thenify(function(padID, html, callback)
|
||||||
{
|
{
|
||||||
// html is required
|
// html is required
|
||||||
if (typeof html !== "string") {
|
if (typeof html !== "string") {
|
||||||
|
@ -395,7 +396,7 @@ exports.setHTML = function(padID, html, callback)
|
||||||
padMessageHandler.updatePadClients(pad, callback);
|
padMessageHandler.updatePadClients(pad, callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/******************/
|
/******************/
|
||||||
/**CHAT FUNCTIONS */
|
/**CHAT FUNCTIONS */
|
||||||
|
@ -413,7 +414,7 @@ Example returns:
|
||||||
|
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getChatHistory = function(padID, start, end, callback)
|
exports.getChatHistory = thenify(function(padID, start, end, callback)
|
||||||
{
|
{
|
||||||
if (start && end) {
|
if (start && end) {
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
|
@ -458,7 +459,7 @@ exports.getChatHistory = function(padID, start, end, callback)
|
||||||
callback(null, {messages: msgs});
|
callback(null, {messages: msgs});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
appendChatMessage(padID, text, authorID, time), creates a chat message for the pad id, time is a timestamp
|
appendChatMessage(padID, text, authorID, time), creates a chat message for the pad id, time is a timestamp
|
||||||
|
@ -468,7 +469,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.appendChatMessage = function(padID, text, authorID, time, callback)
|
exports.appendChatMessage = thenify(function(padID, text, authorID, time, callback)
|
||||||
{
|
{
|
||||||
// text is required
|
// text is required
|
||||||
if (typeof text !== "string") {
|
if (typeof text !== "string") {
|
||||||
|
@ -486,7 +487,7 @@ exports.appendChatMessage = function(padID, text, authorID, time, callback)
|
||||||
padMessageHandler.sendChatMessageToPadClients(time, authorID, text, padID);
|
padMessageHandler.sendChatMessageToPadClients(time, authorID, text, padID);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
}
|
});
|
||||||
|
|
||||||
/*****************/
|
/*****************/
|
||||||
/**PAD FUNCTIONS */
|
/**PAD FUNCTIONS */
|
||||||
|
@ -500,7 +501,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {revisions: 56}}
|
{code: 0, message:"ok", data: {revisions: 56}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getRevisionsCount = function(padID, callback)
|
exports.getRevisionsCount = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// get the pad
|
// get the pad
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
|
@ -508,7 +509,7 @@ exports.getRevisionsCount = function(padID, callback)
|
||||||
|
|
||||||
callback(null, {revisions: pad.getHeadRevisionNumber()});
|
callback(null, {revisions: pad.getHeadRevisionNumber()});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getSavedRevisionsCount(padID) returns the number of saved revisions of this pad
|
getSavedRevisionsCount(padID) returns the number of saved revisions of this pad
|
||||||
|
@ -518,7 +519,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {savedRevisions: 42}}
|
{code: 0, message:"ok", data: {savedRevisions: 42}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getSavedRevisionsCount = function(padID, callback)
|
exports.getSavedRevisionsCount = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// get the pad
|
// get the pad
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
|
@ -526,7 +527,7 @@ exports.getSavedRevisionsCount = function(padID, callback)
|
||||||
|
|
||||||
callback(null, {savedRevisions: pad.getSavedRevisionsNumber()});
|
callback(null, {savedRevisions: pad.getSavedRevisionsNumber()});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
listSavedRevisions(padID) returns the list of saved revisions of this pad
|
listSavedRevisions(padID) returns the list of saved revisions of this pad
|
||||||
|
@ -536,7 +537,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {savedRevisions: [2, 42, 1337]}}
|
{code: 0, message:"ok", data: {savedRevisions: [2, 42, 1337]}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.listSavedRevisions = function(padID, callback)
|
exports.listSavedRevisions = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// get the pad
|
// get the pad
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
|
@ -544,7 +545,7 @@ exports.listSavedRevisions = function(padID, callback)
|
||||||
|
|
||||||
callback(null, {savedRevisions: pad.getSavedRevisionsList()});
|
callback(null, {savedRevisions: pad.getSavedRevisionsList()});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
saveRevision(padID) returns the list of saved revisions of this pad
|
saveRevision(padID) returns the list of saved revisions of this pad
|
||||||
|
@ -554,7 +555,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.saveRevision = function(padID, rev, callback)
|
exports.saveRevision = thenify(function(padID, rev, callback)
|
||||||
{
|
{
|
||||||
// check if rev is a number
|
// check if rev is a number
|
||||||
if (rev !== undefined && typeof rev !== "number") {
|
if (rev !== undefined && typeof rev !== "number") {
|
||||||
|
@ -601,7 +602,7 @@ exports.saveRevision = function(padID, rev, callback)
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getLastEdited(padID) returns the timestamp of the last revision of the pad
|
getLastEdited(padID) returns the timestamp of the last revision of the pad
|
||||||
|
@ -611,7 +612,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {lastEdited: 1340815946602}}
|
{code: 0, message:"ok", data: {lastEdited: 1340815946602}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getLastEdited = function(padID, callback)
|
exports.getLastEdited = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// get the pad
|
// get the pad
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
|
@ -622,7 +623,7 @@ exports.getLastEdited = function(padID, callback)
|
||||||
callback(null, {lastEdited: value});
|
callback(null, {lastEdited: value});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
createPad(padName [, text]) creates a new pad in this group
|
createPad(padName [, text]) creates a new pad in this group
|
||||||
|
@ -632,7 +633,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"pad does already exist", data: null}
|
{code: 1, message:"pad does already exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.createPad = function(padID, text, callback)
|
exports.createPad = thenify(function(padID, text, callback)
|
||||||
{
|
{
|
||||||
if (padID) {
|
if (padID) {
|
||||||
// ensure there is no $ in the padID
|
// ensure there is no $ in the padID
|
||||||
|
@ -653,7 +654,7 @@ exports.createPad = function(padID, text, callback)
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
deletePad(padID) deletes a pad
|
deletePad(padID) deletes a pad
|
||||||
|
@ -663,14 +664,14 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.deletePad = function(padID, callback)
|
exports.deletePad = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
|
||||||
pad.remove(callback);
|
pad.remove(callback);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
/**
|
/**
|
||||||
restoreRevision(padID, [rev]) Restores revision from past as new changeset
|
restoreRevision(padID, [rev]) Restores revision from past as new changeset
|
||||||
|
|
||||||
|
@ -679,7 +680,7 @@ exports.deletePad = function(padID, callback)
|
||||||
{code:0, message:"ok", data:null}
|
{code:0, message:"ok", data:null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.restoreRevision = function(padID, rev, callback)
|
exports.restoreRevision = thenify(function(padID, rev, callback)
|
||||||
{
|
{
|
||||||
// check if rev is a number
|
// check if rev is a number
|
||||||
if (rev !== undefined && typeof rev !== "number") {
|
if (rev !== undefined && typeof rev !== "number") {
|
||||||
|
@ -762,7 +763,7 @@ exports.restoreRevision = function(padID, rev, callback)
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
copyPad(sourceID, destinationID[, force=false]) copies a pad. If force is true,
|
copyPad(sourceID, destinationID[, force=false]) copies a pad. If force is true,
|
||||||
|
@ -773,14 +774,14 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {padID: destinationID}}
|
{code: 0, message:"ok", data: {padID: destinationID}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.copyPad = function(sourceID, destinationID, force, callback)
|
exports.copyPad = thenify(function(sourceID, destinationID, force, callback)
|
||||||
{
|
{
|
||||||
getPadSafe(sourceID, true, function(err, pad) {
|
getPadSafe(sourceID, true, function(err, pad) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
|
||||||
pad.copy(destinationID, force, callback);
|
pad.copy(destinationID, force, callback);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
movePad(sourceID, destinationID[, force=false]) moves a pad. If force is true,
|
movePad(sourceID, destinationID[, force=false]) moves a pad. If force is true,
|
||||||
|
@ -791,7 +792,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {padID: destinationID}}
|
{code: 0, message:"ok", data: {padID: destinationID}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.movePad = function(sourceID, destinationID, force, callback)
|
exports.movePad = thenify(function(sourceID, destinationID, force, callback)
|
||||||
{
|
{
|
||||||
getPadSafe(sourceID, true, function(err, pad) {
|
getPadSafe(sourceID, true, function(err, pad) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
@ -801,7 +802,7 @@ exports.movePad = function(sourceID, destinationID, force, callback)
|
||||||
pad.remove(callback);
|
pad.remove(callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
/**
|
/**
|
||||||
getReadOnlyLink(padID) returns the read only link of a pad
|
getReadOnlyLink(padID) returns the read only link of a pad
|
||||||
|
|
||||||
|
@ -810,7 +811,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getReadOnlyID = function(padID, callback)
|
exports.getReadOnlyID = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// we don't need the pad object, but this function does all the security stuff for us
|
// we don't need the pad object, but this function does all the security stuff for us
|
||||||
getPadSafe(padID, true, function(err) {
|
getPadSafe(padID, true, function(err) {
|
||||||
|
@ -822,7 +823,7 @@ exports.getReadOnlyID = function(padID, callback)
|
||||||
callback(null, {readOnlyID: readOnlyId});
|
callback(null, {readOnlyID: readOnlyId});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getPadID(roID) returns the padID of a pad based on the readonlyID(roID)
|
getPadID(roID) returns the padID of a pad based on the readonlyID(roID)
|
||||||
|
@ -832,7 +833,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {padID: padID}}
|
{code: 0, message:"ok", data: {padID: padID}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getPadID = function(roID, callback)
|
exports.getPadID = thenify(function(roID, callback)
|
||||||
{
|
{
|
||||||
// get the PadId
|
// get the PadId
|
||||||
readOnlyManager.getPadId(roID, function(err, retrievedPadID) {
|
readOnlyManager.getPadId(roID, function(err, retrievedPadID) {
|
||||||
|
@ -845,7 +846,7 @@ exports.getPadID = function(roID, callback)
|
||||||
|
|
||||||
callback(null, {padID: retrievedPadID});
|
callback(null, {padID: retrievedPadID});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
setPublicStatus(padID, publicStatus) sets a boolean for the public status of a pad
|
setPublicStatus(padID, publicStatus) sets a boolean for the public status of a pad
|
||||||
|
@ -855,7 +856,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.setPublicStatus = function(padID, publicStatus, callback)
|
exports.setPublicStatus = thenify(function(padID, publicStatus, callback)
|
||||||
{
|
{
|
||||||
// ensure this is a group pad
|
// ensure this is a group pad
|
||||||
if (padID && padID.indexOf("$") === -1) {
|
if (padID && padID.indexOf("$") === -1) {
|
||||||
|
@ -876,7 +877,7 @@ exports.setPublicStatus = function(padID, publicStatus, callback)
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getPublicStatus(padID) return true of false
|
getPublicStatus(padID) return true of false
|
||||||
|
@ -886,7 +887,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {publicStatus: true}}
|
{code: 0, message:"ok", data: {publicStatus: true}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getPublicStatus = function(padID, callback)
|
exports.getPublicStatus = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// ensure this is a group pad
|
// ensure this is a group pad
|
||||||
if (padID && padID.indexOf("$") == -1) {
|
if (padID && padID.indexOf("$") == -1) {
|
||||||
|
@ -900,7 +901,7 @@ exports.getPublicStatus = function(padID, callback)
|
||||||
|
|
||||||
callback(null, {publicStatus: pad.getPublicStatus()});
|
callback(null, {publicStatus: pad.getPublicStatus()});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
setPassword(padID, password) returns ok or a error message
|
setPassword(padID, password) returns ok or a error message
|
||||||
|
@ -910,7 +911,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: null}
|
{code: 0, message:"ok", data: null}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.setPassword = function(padID, password, callback)
|
exports.setPassword = thenify(function(padID, password, callback)
|
||||||
{
|
{
|
||||||
// ensure this is a group pad
|
// ensure this is a group pad
|
||||||
if (padID && padID.indexOf("$") == -1) {
|
if (padID && padID.indexOf("$") == -1) {
|
||||||
|
@ -927,7 +928,7 @@ exports.setPassword = function(padID, password, callback)
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
isPasswordProtected(padID) returns true or false
|
isPasswordProtected(padID) returns true or false
|
||||||
|
@ -937,7 +938,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {passwordProtection: true}}
|
{code: 0, message:"ok", data: {passwordProtection: true}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.isPasswordProtected = function(padID, callback)
|
exports.isPasswordProtected = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// ensure this is a group pad
|
// ensure this is a group pad
|
||||||
if (padID && padID.indexOf("$") == -1) {
|
if (padID && padID.indexOf("$") == -1) {
|
||||||
|
@ -951,7 +952,7 @@ exports.isPasswordProtected = function(padID, callback)
|
||||||
|
|
||||||
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
|
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
listAuthorsOfPad(padID) returns an array of authors who contributed to this pad
|
listAuthorsOfPad(padID) returns an array of authors who contributed to this pad
|
||||||
|
@ -961,7 +962,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {authorIDs : ["a.s8oes9dhwrvt0zif", "a.akf8finncvomlqva"]}
|
{code: 0, message:"ok", data: {authorIDs : ["a.s8oes9dhwrvt0zif", "a.akf8finncvomlqva"]}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.listAuthorsOfPad = function(padID, callback)
|
exports.listAuthorsOfPad = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// get the pad
|
// get the pad
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
|
@ -969,7 +970,7 @@ exports.listAuthorsOfPad = function(padID, callback)
|
||||||
|
|
||||||
callback(null, {authorIDs: pad.getAllAuthors()});
|
callback(null, {authorIDs: pad.getAllAuthors()});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
sendClientsMessage(padID, msg) sends a message to all clients connected to the
|
sendClientsMessage(padID, msg) sends a message to all clients connected to the
|
||||||
|
@ -994,7 +995,7 @@ Example returns:
|
||||||
{code: 1, message:"padID does not exist"}
|
{code: 1, message:"padID does not exist"}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.sendClientsMessage = function(padID, msg, callback) {
|
exports.sendClientsMessage = thenify(function(padID, msg, callback) {
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
if (ERR(err, callback)) {
|
if (ERR(err, callback)) {
|
||||||
return;
|
return;
|
||||||
|
@ -1002,7 +1003,7 @@ exports.sendClientsMessage = function(padID, msg, callback) {
|
||||||
|
|
||||||
padMessageHandler.handleCustomMessage(padID, msg, callback);
|
padMessageHandler.handleCustomMessage(padID, msg, callback);
|
||||||
} );
|
} );
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
checkToken() returns ok when the current api token is valid
|
checkToken() returns ok when the current api token is valid
|
||||||
|
@ -1012,10 +1013,10 @@ Example returns:
|
||||||
{"code":0,"message":"ok","data":null}
|
{"code":0,"message":"ok","data":null}
|
||||||
{"code":4,"message":"no or wrong API Key","data":null}
|
{"code":4,"message":"no or wrong API Key","data":null}
|
||||||
*/
|
*/
|
||||||
exports.checkToken = function(callback)
|
exports.checkToken = thenify(function(callback)
|
||||||
{
|
{
|
||||||
callback();
|
callback();
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getChatHead(padID) returns the chatHead (last number of the last chat-message) of the pad
|
getChatHead(padID) returns the chatHead (last number of the last chat-message) of the pad
|
||||||
|
@ -1025,7 +1026,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {chatHead: 42}}
|
{code: 0, message:"ok", data: {chatHead: 42}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{code: 1, message:"padID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.getChatHead = function(padID, callback)
|
exports.getChatHead = thenify(function(padID, callback)
|
||||||
{
|
{
|
||||||
// get the pad
|
// get the pad
|
||||||
getPadSafe(padID, true, function(err, pad) {
|
getPadSafe(padID, true, function(err, pad) {
|
||||||
|
@ -1033,7 +1034,7 @@ exports.getChatHead = function(padID, callback)
|
||||||
|
|
||||||
callback(null, {chatHead: pad.chatHead});
|
callback(null, {chatHead: pad.chatHead});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
createDiffHTML(padID, startRev, endRev) returns an object of diffs from 2 points in a pad
|
createDiffHTML(padID, startRev, endRev) returns an object of diffs from 2 points in a pad
|
||||||
|
@ -1043,7 +1044,7 @@ Example returns:
|
||||||
{"code":0,"message":"ok","data":{"html":"<style>\n.authora_HKIv23mEbachFYfH {background-color: #a979d9}\n.authora_n4gEeMLsv1GivNeh {background-color: #a9b5d9}\n.removed {text-decoration: line-through; -ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=80)'; filter: alpha(opacity=80); opacity: 0.8; }\n</style>Welcome to Etherpad!<br><br>This pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!<br><br>Get involved with Etherpad at <a href=\"http://etherpad.org\">http://etherpad.org</a><br><span class=\"authora_HKIv23mEbachFYfH\">aw</span><br><br>","authors":["a.HKIv23mEbachFYfH",""]}}
|
{"code":0,"message":"ok","data":{"html":"<style>\n.authora_HKIv23mEbachFYfH {background-color: #a979d9}\n.authora_n4gEeMLsv1GivNeh {background-color: #a9b5d9}\n.removed {text-decoration: line-through; -ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=80)'; filter: alpha(opacity=80); opacity: 0.8; }\n</style>Welcome to Etherpad!<br><br>This pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!<br><br>Get involved with Etherpad at <a href=\"http://etherpad.org\">http://etherpad.org</a><br><span class=\"authora_HKIv23mEbachFYfH\">aw</span><br><br>","authors":["a.HKIv23mEbachFYfH",""]}}
|
||||||
{"code":4,"message":"no or wrong API Key","data":null}
|
{"code":4,"message":"no or wrong API Key","data":null}
|
||||||
*/
|
*/
|
||||||
exports.createDiffHTML = function(padID, startRev, endRev, callback) {
|
exports.createDiffHTML = thenify(function(padID, startRev, endRev, callback) {
|
||||||
// check if startRev is a number
|
// check if startRev is a number
|
||||||
if (startRev !== undefined && typeof startRev !== "number") {
|
if (startRev !== undefined && typeof startRev !== "number") {
|
||||||
// try to parse the number
|
// try to parse the number
|
||||||
|
@ -1104,7 +1105,7 @@ exports.createDiffHTML = function(padID, startRev, endRev, callback) {
|
||||||
callback(err, {html: html, authors: authors})
|
callback(err, {html: html, authors: authors})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/******************************/
|
/******************************/
|
||||||
/** INTERNAL HELPER FUNCTIONS */
|
/** INTERNAL HELPER FUNCTIONS */
|
||||||
|
|
|
@ -22,6 +22,7 @@ var ERR = require("async-stacktrace");
|
||||||
var db = require("./DB").db;
|
var db = require("./DB").db;
|
||||||
var customError = require("../utils/customError");
|
var customError = require("../utils/customError");
|
||||||
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
exports.getColorPalette = function() {
|
exports.getColorPalette = function() {
|
||||||
return [
|
return [
|
||||||
|
@ -39,7 +40,7 @@ exports.getColorPalette = function() {
|
||||||
/**
|
/**
|
||||||
* Checks if the author exists
|
* Checks if the author exists
|
||||||
*/
|
*/
|
||||||
exports.doesAuthorExists = function(authorID, callback)
|
exports.doesAuthorExists = thenify(function(authorID, callback)
|
||||||
{
|
{
|
||||||
// check if the database entry of this author exists
|
// check if the database entry of this author exists
|
||||||
db.get("globalAuthor:" + authorID, function(err, author) {
|
db.get("globalAuthor:" + authorID, function(err, author) {
|
||||||
|
@ -47,14 +48,14 @@ exports.doesAuthorExists = function(authorID, callback)
|
||||||
|
|
||||||
callback(null, author !== null);
|
callback(null, author !== null);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the AuthorID for a token.
|
* Returns the AuthorID for a token.
|
||||||
* @param {String} token The token
|
* @param {String} token The token
|
||||||
* @param {Function} callback callback (err, author)
|
* @param {Function} callback callback (err, author)
|
||||||
*/
|
*/
|
||||||
exports.getAuthor4Token = function(token, callback)
|
exports.getAuthor4Token = thenify(function(token, callback)
|
||||||
{
|
{
|
||||||
mapAuthorWithDBKey("token2author", token, function(err, author) {
|
mapAuthorWithDBKey("token2author", token, function(err, author) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
@ -62,7 +63,7 @@ exports.getAuthor4Token = function(token, callback)
|
||||||
// return only the sub value authorID
|
// return only the sub value authorID
|
||||||
callback(null, author ? author.authorID : author);
|
callback(null, author ? author.authorID : author);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the AuthorID for a mapper.
|
* Returns the AuthorID for a mapper.
|
||||||
|
@ -70,7 +71,7 @@ exports.getAuthor4Token = function(token, callback)
|
||||||
* @param {String} name The name of the author (optional)
|
* @param {String} name The name of the author (optional)
|
||||||
* @param {Function} callback callback (err, author)
|
* @param {Function} callback callback (err, author)
|
||||||
*/
|
*/
|
||||||
exports.createAuthorIfNotExistsFor = function(authorMapper, name, callback)
|
exports.createAuthorIfNotExistsFor = thenify(function(authorMapper, name, callback)
|
||||||
{
|
{
|
||||||
mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author) {
|
mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
@ -83,7 +84,7 @@ exports.createAuthorIfNotExistsFor = function(authorMapper, name, callback)
|
||||||
// return the authorID
|
// return the authorID
|
||||||
callback(null, author);
|
callback(null, author);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the AuthorID for a mapper. We can map using a mapperkey,
|
* Returns the AuthorID for a mapper. We can map using a mapperkey,
|
||||||
|
@ -126,7 +127,7 @@ function mapAuthorWithDBKey (mapperkey, mapper, callback)
|
||||||
* Internal function that creates the database entry for an author
|
* Internal function that creates the database entry for an author
|
||||||
* @param {String} name The name of the author
|
* @param {String} name The name of the author
|
||||||
*/
|
*/
|
||||||
exports.createAuthor = function(name, callback)
|
exports.createAuthor = thenify(function(name, callback)
|
||||||
{
|
{
|
||||||
// create the new author name
|
// create the new author name
|
||||||
var author = "a." + randomString(16);
|
var author = "a." + randomString(16);
|
||||||
|
@ -142,27 +143,27 @@ exports.createAuthor = function(name, callback)
|
||||||
db.set("globalAuthor:" + author, authorObj);
|
db.set("globalAuthor:" + author, authorObj);
|
||||||
|
|
||||||
callback(null, {authorID: author});
|
callback(null, {authorID: author});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Author Obj of the author
|
* Returns the Author Obj of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {Function} callback callback(err, authorObj)
|
* @param {Function} callback callback(err, authorObj)
|
||||||
*/
|
*/
|
||||||
exports.getAuthor = function(author, callback)
|
exports.getAuthor = thenify(function(author, callback)
|
||||||
{
|
{
|
||||||
db.get("globalAuthor:" + author, callback);
|
db.get("globalAuthor:" + author, callback);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the color Id of the author
|
* Returns the color Id of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {Function} callback callback(err, colorId)
|
* @param {Function} callback callback(err, colorId)
|
||||||
*/
|
*/
|
||||||
exports.getAuthorColorId = function(author, callback)
|
exports.getAuthorColorId = thenify(function(author, callback)
|
||||||
{
|
{
|
||||||
db.getSub("globalAuthor:" + author, ["colorId"], callback);
|
db.getSub("globalAuthor:" + author, ["colorId"], callback);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color Id of the author
|
* Sets the color Id of the author
|
||||||
|
@ -170,20 +171,20 @@ exports.getAuthorColorId = function(author, callback)
|
||||||
* @param {String} colorId The color id of the author
|
* @param {String} colorId The color id of the author
|
||||||
* @param {Function} callback (optional)
|
* @param {Function} callback (optional)
|
||||||
*/
|
*/
|
||||||
exports.setAuthorColorId = function(author, colorId, callback)
|
exports.setAuthorColorId = thenify(function(author, colorId, callback)
|
||||||
{
|
{
|
||||||
db.setSub("globalAuthor:" + author, ["colorId"], colorId, callback);
|
db.setSub("globalAuthor:" + author, ["colorId"], colorId, callback);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the author
|
* Returns the name of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {Function} callback callback(err, name)
|
* @param {Function} callback callback(err, name)
|
||||||
*/
|
*/
|
||||||
exports.getAuthorName = function(author, callback)
|
exports.getAuthorName = thenify(function(author, callback)
|
||||||
{
|
{
|
||||||
db.getSub("globalAuthor:" + author, ["name"], callback);
|
db.getSub("globalAuthor:" + author, ["name"], callback);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name of the author
|
* Sets the name of the author
|
||||||
|
@ -191,17 +192,17 @@ exports.getAuthorName = function(author, callback)
|
||||||
* @param {String} name The name of the author
|
* @param {String} name The name of the author
|
||||||
* @param {Function} callback (optional)
|
* @param {Function} callback (optional)
|
||||||
*/
|
*/
|
||||||
exports.setAuthorName = function(author, name, callback)
|
exports.setAuthorName = thenify(function(author, name, callback)
|
||||||
{
|
{
|
||||||
db.setSub("globalAuthor:" + author, ["name"], name, callback);
|
db.setSub("globalAuthor:" + author, ["name"], name, callback);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all pads this author contributed to
|
* Returns an array of all pads this author contributed to
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {Function} callback (optional)
|
* @param {Function} callback (optional)
|
||||||
*/
|
*/
|
||||||
exports.listPadsOfAuthor = function(authorID, callback)
|
exports.listPadsOfAuthor = thenify(function(authorID, callback)
|
||||||
{
|
{
|
||||||
/* There are two other places where this array is manipulated:
|
/* There are two other places where this array is manipulated:
|
||||||
* (1) When the author is added to a pad, the author object is also updated
|
* (1) When the author is added to a pad, the author object is also updated
|
||||||
|
@ -230,7 +231,7 @@ exports.listPadsOfAuthor = function(authorID, callback)
|
||||||
|
|
||||||
callback(null, {padIDs: pads});
|
callback(null, {padIDs: pads});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new pad to the list of contributions
|
* Adds a new pad to the list of contributions
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
var ueberDB = require("ueberdb2");
|
var ueberDB = require("ueberdb2");
|
||||||
var settings = require("../utils/Settings");
|
var settings = require("../utils/Settings");
|
||||||
var log4js = require('log4js');
|
var log4js = require('log4js');
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
// set database settings
|
// set database settings
|
||||||
var db = new ueberDB.database(settings.dbType, settings.dbSettings, null, log4js.getLogger("ueberDB"));
|
var db = new ueberDB.database(settings.dbType, settings.dbSettings, null, log4js.getLogger("ueberDB"));
|
||||||
|
@ -35,7 +36,7 @@ exports.db = null;
|
||||||
* Initalizes the database with the settings provided by the settings module
|
* Initalizes the database with the settings provided by the settings module
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
function init(callback) {
|
exports.init = thenify(function (callback) {
|
||||||
// initalize the database async
|
// initalize the database async
|
||||||
db.init(function(err) {
|
db.init(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -49,20 +50,4 @@ function init(callback) {
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Initalizes the database with the settings provided by the settings module
|
|
||||||
* If the callback is not supplied a Promise is returned instead.
|
|
||||||
* @param {Function} callback
|
|
||||||
*/
|
|
||||||
exports.init = function(callback)
|
|
||||||
{
|
|
||||||
if (callback === undefined) {
|
|
||||||
return new Promise(resolve => init(resolve));
|
|
||||||
} else if (typeof callback === "function") {
|
|
||||||
init(callback);
|
|
||||||
} else {
|
|
||||||
throw new TypeError("DB.init callback parameter");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,8 +25,9 @@ var db = require("./DB").db;
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
var padManager = require("./PadManager");
|
var padManager = require("./PadManager");
|
||||||
var sessionManager = require("./SessionManager");
|
var sessionManager = require("./SessionManager");
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
exports.listAllGroups = function(callback) {
|
exports.listAllGroups = thenify(function(callback) {
|
||||||
db.get("groups", function (err, groups) {
|
db.get("groups", function (err, groups) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
|
||||||
|
@ -43,9 +44,9 @@ exports.listAllGroups = function(callback) {
|
||||||
}
|
}
|
||||||
callback(null, {groupIDs: groupIDs});
|
callback(null, {groupIDs: groupIDs});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.deleteGroup = function(groupID, callback)
|
exports.deleteGroup = thenify(function(groupID, callback)
|
||||||
{
|
{
|
||||||
var group;
|
var group;
|
||||||
|
|
||||||
|
@ -158,18 +159,18 @@ exports.deleteGroup = function(groupID, callback)
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.doesGroupExist = function(groupID, callback)
|
exports.doesGroupExist = thenify(function(groupID, callback)
|
||||||
{
|
{
|
||||||
// try to get the group entry
|
// try to get the group entry
|
||||||
db.get("group:" + groupID, function (err, group) {
|
db.get("group:" + groupID, function (err, group) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
callback(null, group != null);
|
callback(null, group != null);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.createGroup = function(callback)
|
exports.createGroup = thenify(function(callback)
|
||||||
{
|
{
|
||||||
// search for non existing groupID
|
// search for non existing groupID
|
||||||
var groupID = "g." + randomString(16);
|
var groupID = "g." + randomString(16);
|
||||||
|
@ -195,9 +196,9 @@ exports.createGroup = function(callback)
|
||||||
callback(null, {groupID: groupID});
|
callback(null, {groupID: groupID});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.createGroupIfNotExistsFor = function(groupMapper, callback)
|
exports.createGroupIfNotExistsFor = thenify(function(groupMapper, callback)
|
||||||
{
|
{
|
||||||
// ensure mapper is optional
|
// ensure mapper is optional
|
||||||
if (typeof groupMapper !== "string") {
|
if (typeof groupMapper !== "string") {
|
||||||
|
@ -237,9 +238,9 @@ exports.createGroupIfNotExistsFor = function(groupMapper, callback)
|
||||||
// there is no group for this mapper, let's create a group
|
// there is no group for this mapper, let's create a group
|
||||||
createGroupForMapper(callback)
|
createGroupForMapper(callback)
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.createGroupPad = function(groupID, padName, text, callback)
|
exports.createGroupPad = thenify(function(groupID, padName, text, callback)
|
||||||
{
|
{
|
||||||
// create the padID
|
// create the padID
|
||||||
var padID = groupID + "$" + padName;
|
var padID = groupID + "$" + padName;
|
||||||
|
@ -297,9 +298,9 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
||||||
|
|
||||||
callback(null, {padID: padID});
|
callback(null, {padID: padID});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.listPads = function(groupID, callback)
|
exports.listPads = thenify(function(groupID, callback)
|
||||||
{
|
{
|
||||||
exports.doesGroupExist(groupID, function(err, exists) {
|
exports.doesGroupExist(groupID, function(err, exists) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
@ -321,4 +322,4 @@ exports.listPads = function(groupID, callback)
|
||||||
callback(null, {padIDs: pads});
|
callback(null, {padIDs: pads});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
|
@ -18,6 +18,7 @@ var readOnlyManager = require("./ReadOnlyManager");
|
||||||
var crypto = require("crypto");
|
var crypto = require("crypto");
|
||||||
var randomString = require("../utils/randomstring");
|
var randomString = require("../utils/randomstring");
|
||||||
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
// serialization/deserialization attributes
|
// serialization/deserialization attributes
|
||||||
var attributeBlackList = ["id"];
|
var attributeBlackList = ["id"];
|
||||||
|
@ -131,22 +132,22 @@ Pad.prototype.saveToDatabase = function saveToDatabase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get time of last edit (changeset application)
|
// get time of last edit (changeset application)
|
||||||
Pad.prototype.getLastEdit = function getLastEdit(callback) {
|
Pad.prototype.getLastEdit = thenify(function getLastEdit(callback) {
|
||||||
var revNum = this.getHeadRevisionNumber();
|
var revNum = this.getHeadRevisionNumber();
|
||||||
db.getSub("pad:" + this.id + ":revs:" + revNum, ["meta", "timestamp"], callback);
|
db.getSub("pad:" + this.id + ":revs:" + revNum, ["meta", "timestamp"], callback);
|
||||||
}
|
});
|
||||||
|
|
||||||
Pad.prototype.getRevisionChangeset = function getRevisionChangeset(revNum, callback) {
|
Pad.prototype.getRevisionChangeset = thenify(function getRevisionChangeset(revNum, callback) {
|
||||||
db.getSub("pad:" + this.id + ":revs:" + revNum, ["changeset"], callback);
|
db.getSub("pad:" + this.id + ":revs:" + revNum, ["changeset"], callback);
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.getRevisionAuthor = function getRevisionAuthor(revNum, callback) {
|
Pad.prototype.getRevisionAuthor = thenify(function getRevisionAuthor(revNum, callback) {
|
||||||
db.getSub("pad:" + this.id + ":revs:" + revNum, ["meta", "author"], callback);
|
db.getSub("pad:" + this.id + ":revs:" + revNum, ["meta", "author"], callback);
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.getRevisionDate = function getRevisionDate(revNum, callback) {
|
Pad.prototype.getRevisionDate = thenify(function getRevisionDate(revNum, callback) {
|
||||||
db.getSub("pad:" + this.id + ":revs:" + revNum, ["meta", "timestamp"], callback);
|
db.getSub("pad:" + this.id + ":revs:" + revNum, ["meta", "timestamp"], callback);
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.getAllAuthors = function getAllAuthors() {
|
Pad.prototype.getAllAuthors = function getAllAuthors() {
|
||||||
var authors = [];
|
var authors = [];
|
||||||
|
@ -160,7 +161,7 @@ Pad.prototype.getAllAuthors = function getAllAuthors() {
|
||||||
return authors;
|
return authors;
|
||||||
};
|
};
|
||||||
|
|
||||||
Pad.prototype.getInternalRevisionAText = function getInternalRevisionAText(targetRev, callback) {
|
Pad.prototype.getInternalRevisionAText = thenify(function getInternalRevisionAText(targetRev, callback) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
var keyRev = this.getKeyRevisionNumber(targetRev);
|
var keyRev = this.getKeyRevisionNumber(targetRev);
|
||||||
|
@ -228,13 +229,13 @@ Pad.prototype.getInternalRevisionAText = function getInternalRevisionAText(targe
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
callback(null, atext);
|
callback(null, atext);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.getRevision = function getRevisionChangeset(revNum, callback) {
|
Pad.prototype.getRevision = thenify(function getRevisionChangeset(revNum, callback) {
|
||||||
db.get("pad:" + this.id + ":revs:" + revNum, callback);
|
db.get("pad:" + this.id + ":revs:" + revNum, callback);
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.getAllAuthorColors = function getAllAuthorColors(callback) {
|
Pad.prototype.getAllAuthorColors = thenify(function getAllAuthorColors(callback) {
|
||||||
var authors = this.getAllAuthors();
|
var authors = this.getAllAuthors();
|
||||||
var returnTable = {};
|
var returnTable = {};
|
||||||
var colorPalette = authorManager.getColorPalette();
|
var colorPalette = authorManager.getColorPalette();
|
||||||
|
@ -254,7 +255,7 @@ Pad.prototype.getAllAuthorColors = function getAllAuthorColors(callback) {
|
||||||
function(err) {
|
function(err) {
|
||||||
callback(err, returnTable);
|
callback(err, returnTable);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.getValidRevisionRange = function getValidRevisionRange(startRev, endRev) {
|
Pad.prototype.getValidRevisionRange = function getValidRevisionRange(startRev, endRev) {
|
||||||
startRev = parseInt(startRev, 10);
|
startRev = parseInt(startRev, 10);
|
||||||
|
@ -325,7 +326,7 @@ Pad.prototype.appendChatMessage = function appendChatMessage(text, userId, time)
|
||||||
this.saveToDatabase();
|
this.saveToDatabase();
|
||||||
};
|
};
|
||||||
|
|
||||||
Pad.prototype.getChatMessage = function getChatMessage(entryNum, callback) {
|
Pad.prototype.getChatMessage = thenify(function getChatMessage(entryNum, callback) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var entry;
|
var entry;
|
||||||
|
|
||||||
|
@ -359,9 +360,9 @@ Pad.prototype.getChatMessage = function getChatMessage(entryNum, callback) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
callback(null, entry);
|
callback(null, entry);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.getChatMessages = function getChatMessages(start, end, callback) {
|
Pad.prototype.getChatMessages = thenify(function getChatMessages(start, end, callback) {
|
||||||
// collect the numbers of chat entries and in which order we need them
|
// collect the numbers of chat entries and in which order we need them
|
||||||
var neededEntries = [];
|
var neededEntries = [];
|
||||||
var order = 0;
|
var order = 0;
|
||||||
|
@ -398,9 +399,9 @@ Pad.prototype.getChatMessages = function getChatMessages(start, end, callback) {
|
||||||
|
|
||||||
callback(null, cleanedEntries);
|
callback(null, cleanedEntries);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.init = function init(text, callback) {
|
Pad.prototype.init = thenify(function init(text, callback) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
// replace text with default text if text isn't set
|
// replace text with default text if text isn't set
|
||||||
|
@ -432,9 +433,9 @@ Pad.prototype.init = function init(text, callback) {
|
||||||
hooks.callAll("padLoad", { 'pad': _this });
|
hooks.callAll("padLoad", { 'pad': _this });
|
||||||
callback(null);
|
callback(null);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.copy = function copy(destinationID, force, callback) {
|
Pad.prototype.copy = thenify(function copy(destinationID, force, callback) {
|
||||||
var sourceID = this.id;
|
var sourceID = this.id;
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var destGroupID;
|
var destGroupID;
|
||||||
|
@ -581,9 +582,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
callback(null, { padID: destinationID });
|
callback(null, { padID: destinationID });
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Pad.prototype.remove = function remove(callback) {
|
Pad.prototype.remove = thenify(function remove(callback) {
|
||||||
var padID = this.id;
|
var padID = this.id;
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
@ -676,7 +677,7 @@ Pad.prototype.remove = function remove(callback) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
// set in db
|
// set in db
|
||||||
Pad.prototype.setPublicStatus = function setPublicStatus(publicStatus) {
|
Pad.prototype.setPublicStatus = function setPublicStatus(publicStatus) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ var ERR = require("async-stacktrace");
|
||||||
var customError = require("../utils/customError");
|
var customError = require("../utils/customError");
|
||||||
var Pad = require("../db/Pad").Pad;
|
var Pad = require("../db/Pad").Pad;
|
||||||
var db = require("./DB").db;
|
var db = require("./DB").db;
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cache of all loaded Pads.
|
* A cache of all loaded Pads.
|
||||||
|
@ -53,7 +54,7 @@ var padList = {
|
||||||
list: [],
|
list: [],
|
||||||
sorted : false,
|
sorted : false,
|
||||||
initiated: false,
|
initiated: false,
|
||||||
init: function(cb) {
|
init: thenify(function(cb) {
|
||||||
db.findKeys("pad:*", "*:*:*", function(err, dbData) {
|
db.findKeys("pad:*", "*:*:*", function(err, dbData) {
|
||||||
if (ERR(err, cb)) return;
|
if (ERR(err, cb)) return;
|
||||||
|
|
||||||
|
@ -68,18 +69,18 @@ var padList = {
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
}),
|
||||||
load: function(cb) {
|
load: thenify(function(cb) {
|
||||||
if (this.initiated) {
|
if (this.initiated) {
|
||||||
cb && cb();
|
cb && cb();
|
||||||
} else {
|
} else {
|
||||||
this.init(cb);
|
this.init(cb);
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
/**
|
/**
|
||||||
* Returns all pads in alphabetical order as array.
|
* Returns all pads in alphabetical order as array.
|
||||||
*/
|
*/
|
||||||
getPads: function(cb) {
|
getPads: thenify(function(cb) {
|
||||||
this.load(function() {
|
this.load(function() {
|
||||||
if (!padList.sorted) {
|
if (!padList.sorted) {
|
||||||
padList.list = padList.list.sort();
|
padList.list = padList.list.sort();
|
||||||
|
@ -88,7 +89,7 @@ var padList = {
|
||||||
|
|
||||||
cb && cb(padList.list);
|
cb && cb(padList.list);
|
||||||
})
|
})
|
||||||
},
|
}),
|
||||||
addPad: function(name) {
|
addPad: function(name) {
|
||||||
if (!this.initiated) return;
|
if (!this.initiated) return;
|
||||||
|
|
||||||
|
@ -125,7 +126,7 @@ var padIdTransforms = [
|
||||||
* @param id A String with the id of the pad
|
* @param id A String with the id of the pad
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
exports.getPad = function(id, text, callback)
|
exports.getPad = thenify(function(id, text, callback)
|
||||||
{
|
{
|
||||||
// check if this is a valid padId
|
// check if this is a valid padId
|
||||||
if (!exports.isValidPadId(id)) {
|
if (!exports.isValidPadId(id)) {
|
||||||
|
@ -177,17 +178,17 @@ exports.getPad = function(id, text, callback)
|
||||||
padList.addPad(id);
|
padList.addPad(id);
|
||||||
callback(null, pad);
|
callback(null, pad);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.listAllPads = function(cb)
|
exports.listAllPads = thenify(function(cb)
|
||||||
{
|
{
|
||||||
padList.getPads(function(list) {
|
padList.getPads(function(list) {
|
||||||
cb && cb(null, {padIDs: list});
|
cb && cb(null, {padIDs: list});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
// checks if a pad exists
|
// checks if a pad exists
|
||||||
exports.doesPadExists = function(padId, callback)
|
exports.doesPadExists = thenify(function(padId, callback)
|
||||||
{
|
{
|
||||||
db.get("pad:" + padId, function(err, value) {
|
db.get("pad:" + padId, function(err, value) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
@ -198,10 +199,10 @@ exports.doesPadExists = function(padId, callback)
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
// returns a sanitized padId, respecting legacy pad id formats
|
// returns a sanitized padId, respecting legacy pad id formats
|
||||||
exports.sanitizePadId = function(padId, callback) {
|
function sanitizePadId(padId, callback) {
|
||||||
var transform_index = arguments[2] || 0;
|
var transform_index = arguments[2] || 0;
|
||||||
|
|
||||||
// we're out of possible transformations, so just return it
|
// we're out of possible transformations, so just return it
|
||||||
|
@ -228,10 +229,19 @@ exports.sanitizePadId = function(padId, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the next transform
|
// check the next transform
|
||||||
exports.sanitizePadId(transformedPadId, callback, transform_index);
|
sanitizePadId(transformedPadId, callback, transform_index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sanitizePadId can't use thenify: single arg callback
|
||||||
|
exports.sanitizePadId = function(padId, callback) {
|
||||||
|
if (callback) {
|
||||||
|
return sanitizePadId(padId, callback);
|
||||||
|
} else {
|
||||||
|
return new Promise(resolve => sanitizePadId(padId, resolve));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.isValidPadId = function(padId)
|
exports.isValidPadId = function(padId)
|
||||||
{
|
{
|
||||||
return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId);
|
return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId);
|
||||||
|
|
|
@ -23,12 +23,13 @@ var ERR = require("async-stacktrace");
|
||||||
var db = require("./DB").db;
|
var db = require("./DB").db;
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
var randomString = require("../utils/randomstring");
|
var randomString = require("../utils/randomstring");
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a read only id for a pad
|
* returns a read only id for a pad
|
||||||
* @param {String} padId the id of the pad
|
* @param {String} padId the id of the pad
|
||||||
*/
|
*/
|
||||||
exports.getReadOnlyId = function (padId, callback)
|
exports.getReadOnlyId = thenify(function (padId, callback)
|
||||||
{
|
{
|
||||||
var readOnlyId;
|
var readOnlyId;
|
||||||
|
|
||||||
|
@ -59,22 +60,22 @@ exports.getReadOnlyId = function (padId, callback)
|
||||||
// return the results
|
// return the results
|
||||||
callback(null, readOnlyId);
|
callback(null, readOnlyId);
|
||||||
})
|
})
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the padId for a read only id
|
* returns the padId for a read only id
|
||||||
* @param {String} readOnlyId read only id
|
* @param {String} readOnlyId read only id
|
||||||
*/
|
*/
|
||||||
exports.getPadId = function(readOnlyId, callback)
|
exports.getPadId = thenify(function(readOnlyId, callback)
|
||||||
{
|
{
|
||||||
db.get("readonly2pad:" + readOnlyId, callback);
|
db.get("readonly2pad:" + readOnlyId, callback);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the padId and readonlyPadId in an object for any id
|
* returns the padId and readonlyPadId in an object for any id
|
||||||
* @param {String} padIdOrReadonlyPadId read only id or real pad id
|
* @param {String} padIdOrReadonlyPadId read only id or real pad id
|
||||||
*/
|
*/
|
||||||
exports.getIds = function(id, callback) {
|
exports.getIds = thenify(function(id, callback) {
|
||||||
if (id.indexOf("r.") == 0) {
|
if (id.indexOf("r.") == 0) {
|
||||||
exports.getPadId(id, function (err, value) {
|
exports.getPadId(id, function (err, value) {
|
||||||
if (ERR(err, callback)) return;
|
if (ERR(err, callback)) return;
|
||||||
|
@ -94,4 +95,4 @@ exports.getIds = function(id, callback) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
|
@ -25,8 +25,9 @@ var db = require("./DB").db;
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
var groupManager = require("./GroupManager");
|
var groupManager = require("./GroupManager");
|
||||||
var authorManager = require("./AuthorManager");
|
var authorManager = require("./AuthorManager");
|
||||||
|
const thenify = require("thenify").withCallback;
|
||||||
|
|
||||||
exports.doesSessionExist = function(sessionID, callback)
|
exports.doesSessionExist = thenify(function(sessionID, callback)
|
||||||
{
|
{
|
||||||
//check if the database entry of this session exists
|
//check if the database entry of this session exists
|
||||||
db.get("session:" + sessionID, function (err, session)
|
db.get("session:" + sessionID, function (err, session)
|
||||||
|
@ -34,12 +35,12 @@ exports.doesSessionExist = function(sessionID, callback)
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
callback(null, session != null);
|
callback(null, session != null);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new session between an author and a group
|
* Creates a new session between an author and a group
|
||||||
*/
|
*/
|
||||||
exports.createSession = function(groupID, authorID, validUntil, callback)
|
exports.createSession = thenify(function(groupID, authorID, validUntil, callback)
|
||||||
{
|
{
|
||||||
var sessionID;
|
var sessionID;
|
||||||
|
|
||||||
|
@ -172,9 +173,9 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
||||||
// return error and sessionID
|
// return error and sessionID
|
||||||
callback(null, {sessionID: sessionID});
|
callback(null, {sessionID: sessionID});
|
||||||
})
|
})
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.getSessionInfo = function(sessionID, callback)
|
exports.getSessionInfo = thenify(function(sessionID, callback)
|
||||||
{
|
{
|
||||||
// check if the database entry of this session exists
|
// check if the database entry of this session exists
|
||||||
db.get("session:" + sessionID, function (err, session)
|
db.get("session:" + sessionID, function (err, session)
|
||||||
|
@ -189,12 +190,12 @@ exports.getSessionInfo = function(sessionID, callback)
|
||||||
callback(null, session);
|
callback(null, session);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a session
|
* Deletes a session
|
||||||
*/
|
*/
|
||||||
exports.deleteSession = function(sessionID, callback)
|
exports.deleteSession = thenify(function(sessionID, callback)
|
||||||
{
|
{
|
||||||
var authorID, groupID;
|
var authorID, groupID;
|
||||||
var group2sessions, author2sessions;
|
var group2sessions, author2sessions;
|
||||||
|
@ -267,9 +268,9 @@ exports.deleteSession = function(sessionID, callback)
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
callback();
|
callback();
|
||||||
})
|
})
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.listSessionsOfGroup = function(groupID, callback)
|
exports.listSessionsOfGroup = thenify(function(groupID, callback)
|
||||||
{
|
{
|
||||||
groupManager.doesGroupExist(groupID, function(err, exists)
|
groupManager.doesGroupExist(groupID, function(err, exists)
|
||||||
{
|
{
|
||||||
|
@ -283,9 +284,9 @@ exports.listSessionsOfGroup = function(groupID, callback)
|
||||||
listSessionsWithDBKey("group2sessions:" + groupID, callback);
|
listSessionsWithDBKey("group2sessions:" + groupID, callback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
exports.listSessionsOfAuthor = function(authorID, callback)
|
exports.listSessionsOfAuthor = thenify(function(authorID, callback)
|
||||||
{
|
{
|
||||||
authorManager.doesAuthorExists(authorID, function(err, exists)
|
authorManager.doesAuthorExists(authorID, function(err, exists)
|
||||||
{
|
{
|
||||||
|
@ -299,7 +300,7 @@ exports.listSessionsOfAuthor = function(authorID, callback)
|
||||||
listSessionsWithDBKey("author2sessions:" + authorID, callback);
|
listSessionsWithDBKey("author2sessions:" + authorID, callback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
// this function is basically the code listSessionsOfAuthor and listSessionsOfGroup has in common
|
// this function is basically the code listSessionsOfAuthor and listSessionsOfGroup has in common
|
||||||
function listSessionsWithDBKey (dbkey, callback)
|
function listSessionsWithDBKey (dbkey, callback)
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
"slide": "1.1.6",
|
"slide": "1.1.6",
|
||||||
"socket.io": "2.1.1",
|
"socket.io": "2.1.1",
|
||||||
"swagger-node-express": "2.1.3",
|
"swagger-node-express": "2.1.3",
|
||||||
|
"thenify": "^3.3.0",
|
||||||
"tinycon": "0.0.1",
|
"tinycon": "0.0.1",
|
||||||
"ueberdb2": "0.4.0",
|
"ueberdb2": "0.4.0",
|
||||||
"uglify-js": "2.6.2",
|
"uglify-js": "2.6.2",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue