mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36: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 cleanText = require("./Pad").cleanText;
|
||||
var PadDiff = require("../utils/padDiff");
|
||||
const thenify = require("thenify").withCallback;
|
||||
|
||||
/**********************/
|
||||
/**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) {
|
||||
if (ERR(err, callback)) return;
|
||||
|
||||
callback(null, {pool: pad.pool});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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
|
||||
if (rev !== undefined && typeof rev !== "number") {
|
||||
|
@ -179,7 +180,7 @@ exports.getRevisionChangeset = function(padID, rev, callback)
|
|||
callback(null, changeset);
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
getText(padID, [rev]) returns the text of a pad
|
||||
|
@ -189,7 +190,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {text:"Welcome Text"}}
|
||||
{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
|
||||
if (rev !== undefined && typeof rev !== "number") {
|
||||
|
@ -242,7 +243,7 @@ exports.getText = function(padID, rev, callback)
|
|||
var padText = exportTxt.getTXTFromAtext(pad, pad.atext);
|
||||
callback(null, {"text": padText});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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:"text too long", data: null}
|
||||
*/
|
||||
exports.setText = function(padID, text, callback)
|
||||
exports.setText = thenify(function(padID, text, callback)
|
||||
{
|
||||
// text is required
|
||||
if (typeof text !== "string") {
|
||||
|
@ -271,7 +272,7 @@ exports.setText = function(padID, text, callback)
|
|||
// update the clients on the pad
|
||||
padMessageHandler.updatePadClients(pad, callback);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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:"text too long", data: null}
|
||||
*/
|
||||
exports.appendText = function(padID, text, callback)
|
||||
exports.appendText = thenify(function(padID, text, callback)
|
||||
{
|
||||
// text is required
|
||||
if (typeof text !== "string") {
|
||||
|
@ -299,7 +300,7 @@ exports.appendText = function(padID, text, callback)
|
|||
// update the clients on the pad
|
||||
padMessageHandler.updatePadClients(pad, callback);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
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: 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 (isNaN(parseInt(rev))) {
|
||||
|
@ -362,7 +363,7 @@ exports.getHTML = function(padID, rev, callback)
|
|||
callback(null, data);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.setHTML = function(padID, html, callback)
|
||||
exports.setHTML = thenify(function(padID, html, callback)
|
||||
{
|
||||
// html is required
|
||||
if (typeof html !== "string") {
|
||||
|
@ -395,7 +396,7 @@ exports.setHTML = function(padID, html, callback)
|
|||
padMessageHandler.updatePadClients(pad, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/******************/
|
||||
/**CHAT FUNCTIONS */
|
||||
|
@ -413,7 +414,7 @@ Example returns:
|
|||
|
||||
{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 < 0) {
|
||||
|
@ -458,7 +459,7 @@ exports.getChatHistory = function(padID, start, end, callback)
|
|||
callback(null, {messages: msgs});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 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
|
||||
if (typeof text !== "string") {
|
||||
|
@ -486,7 +487,7 @@ exports.appendChatMessage = function(padID, text, authorID, time, callback)
|
|||
padMessageHandler.sendChatMessageToPadClients(time, authorID, text, padID);
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
/*****************/
|
||||
/**PAD FUNCTIONS */
|
||||
|
@ -500,7 +501,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {revisions: 56}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getRevisionsCount = function(padID, callback)
|
||||
exports.getRevisionsCount = thenify(function(padID, callback)
|
||||
{
|
||||
// get the pad
|
||||
getPadSafe(padID, true, function(err, pad) {
|
||||
|
@ -508,7 +509,7 @@ exports.getRevisionsCount = function(padID, callback)
|
|||
|
||||
callback(null, {revisions: pad.getHeadRevisionNumber()});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getSavedRevisionsCount = function(padID, callback)
|
||||
exports.getSavedRevisionsCount = thenify(function(padID, callback)
|
||||
{
|
||||
// get the pad
|
||||
getPadSafe(padID, true, function(err, pad) {
|
||||
|
@ -526,7 +527,7 @@ exports.getSavedRevisionsCount = function(padID, callback)
|
|||
|
||||
callback(null, {savedRevisions: pad.getSavedRevisionsNumber()});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.listSavedRevisions = function(padID, callback)
|
||||
exports.listSavedRevisions = thenify(function(padID, callback)
|
||||
{
|
||||
// get the pad
|
||||
getPadSafe(padID, true, function(err, pad) {
|
||||
|
@ -544,7 +545,7 @@ exports.listSavedRevisions = function(padID, callback)
|
|||
|
||||
callback(null, {savedRevisions: pad.getSavedRevisionsList()});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
saveRevision(padID) returns the list of saved revisions of this pad
|
||||
|
@ -554,7 +555,7 @@ Example returns:
|
|||
{code: 0, message:"ok", 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
|
||||
if (rev !== undefined && typeof rev !== "number") {
|
||||
|
@ -601,7 +602,7 @@ exports.saveRevision = function(padID, rev, callback)
|
|||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getLastEdited = function(padID, callback)
|
||||
exports.getLastEdited = thenify(function(padID, callback)
|
||||
{
|
||||
// get the pad
|
||||
getPadSafe(padID, true, function(err, pad) {
|
||||
|
@ -622,7 +623,7 @@ exports.getLastEdited = function(padID, callback)
|
|||
callback(null, {lastEdited: value});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
createPad(padName [, text]) creates a new pad in this group
|
||||
|
@ -632,7 +633,7 @@ Example returns:
|
|||
{code: 0, message:"ok", 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) {
|
||||
// ensure there is no $ in the padID
|
||||
|
@ -653,7 +654,7 @@ exports.createPad = function(padID, text, callback)
|
|||
if (ERR(err, callback)) return;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
deletePad(padID) deletes a pad
|
||||
|
@ -663,14 +664,14 @@ Example returns:
|
|||
{code: 0, message:"ok", 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) {
|
||||
if (ERR(err, callback)) return;
|
||||
|
||||
pad.remove(callback);
|
||||
});
|
||||
}
|
||||
});
|
||||
/**
|
||||
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: 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
|
||||
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,
|
||||
|
@ -773,14 +774,14 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {padID: destinationID}}
|
||||
{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) {
|
||||
if (ERR(err, callback)) return;
|
||||
|
||||
pad.copy(destinationID, force, callback);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 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) {
|
||||
if (ERR(err, callback)) return;
|
||||
|
@ -801,7 +802,7 @@ exports.movePad = function(sourceID, destinationID, force, callback)
|
|||
pad.remove(callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
/**
|
||||
getReadOnlyLink(padID) returns the read only link of a pad
|
||||
|
||||
|
@ -810,7 +811,7 @@ Example returns:
|
|||
{code: 0, message:"ok", 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
|
||||
getPadSafe(padID, true, function(err) {
|
||||
|
@ -822,7 +823,7 @@ exports.getReadOnlyID = function(padID, callback)
|
|||
callback(null, {readOnlyID: readOnlyId});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getPadID = function(roID, callback)
|
||||
exports.getPadID = thenify(function(roID, callback)
|
||||
{
|
||||
// get the PadId
|
||||
readOnlyManager.getPadId(roID, function(err, retrievedPadID) {
|
||||
|
@ -845,7 +846,7 @@ exports.getPadID = function(roID, callback)
|
|||
|
||||
callback(null, {padID: retrievedPadID});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 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
|
||||
if (padID && padID.indexOf("$") === -1) {
|
||||
|
@ -876,7 +877,7 @@ exports.setPublicStatus = function(padID, publicStatus, callback)
|
|||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
getPublicStatus(padID) return true of false
|
||||
|
@ -886,7 +887,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {publicStatus: true}}
|
||||
{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
|
||||
if (padID && padID.indexOf("$") == -1) {
|
||||
|
@ -900,7 +901,7 @@ exports.getPublicStatus = function(padID, callback)
|
|||
|
||||
callback(null, {publicStatus: pad.getPublicStatus()});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
setPassword(padID, password) returns ok or a error message
|
||||
|
@ -910,7 +911,7 @@ Example returns:
|
|||
{code: 0, message:"ok", 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
|
||||
if (padID && padID.indexOf("$") == -1) {
|
||||
|
@ -927,7 +928,7 @@ exports.setPassword = function(padID, password, callback)
|
|||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
isPasswordProtected(padID) returns true or false
|
||||
|
@ -937,7 +938,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {passwordProtection: true}}
|
||||
{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
|
||||
if (padID && padID.indexOf("$") == -1) {
|
||||
|
@ -951,7 +952,7 @@ exports.isPasswordProtected = function(padID, callback)
|
|||
|
||||
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.listAuthorsOfPad = function(padID, callback)
|
||||
exports.listAuthorsOfPad = thenify(function(padID, callback)
|
||||
{
|
||||
// get the pad
|
||||
getPadSafe(padID, true, function(err, pad) {
|
||||
|
@ -969,7 +970,7 @@ exports.listAuthorsOfPad = function(padID, callback)
|
|||
|
||||
callback(null, {authorIDs: pad.getAllAuthors()});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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"}
|
||||
*/
|
||||
|
||||
exports.sendClientsMessage = function(padID, msg, callback) {
|
||||
exports.sendClientsMessage = thenify(function(padID, msg, callback) {
|
||||
getPadSafe(padID, true, function(err, pad) {
|
||||
if (ERR(err, callback)) {
|
||||
return;
|
||||
|
@ -1002,7 +1003,7 @@ exports.sendClientsMessage = function(padID, msg, callback) {
|
|||
|
||||
padMessageHandler.handleCustomMessage(padID, msg, callback);
|
||||
} );
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
checkToken() returns ok when the current api token is valid
|
||||
|
@ -1012,10 +1013,10 @@ Example returns:
|
|||
{"code":0,"message":"ok","data":null}
|
||||
{"code":4,"message":"no or wrong API Key","data":null}
|
||||
*/
|
||||
exports.checkToken = function(callback)
|
||||
exports.checkToken = thenify(function(callback)
|
||||
{
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getChatHead = function(padID, callback)
|
||||
exports.getChatHead = thenify(function(padID, callback)
|
||||
{
|
||||
// get the pad
|
||||
getPadSafe(padID, true, function(err, pad) {
|
||||
|
@ -1033,7 +1034,7 @@ exports.getChatHead = function(padID, callback)
|
|||
|
||||
callback(null, {chatHead: pad.chatHead});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
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":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
|
||||
if (startRev !== undefined && typeof startRev !== "number") {
|
||||
// try to parse the number
|
||||
|
@ -1104,7 +1105,7 @@ exports.createDiffHTML = function(padID, startRev, endRev, callback) {
|
|||
callback(err, {html: html, authors: authors})
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/******************************/
|
||||
/** INTERNAL HELPER FUNCTIONS */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue