mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-13 10:36:52 -04:00
remove trailing whitespace
This commit is contained in:
parent
e1edc8079f
commit
0b6709392b
104 changed files with 1479 additions and 1479 deletions
|
@ -68,7 +68,7 @@ exports.listSessionsOfAuthor = sessionManager.listSessionsOfAuthor;
|
|||
/************************/
|
||||
|
||||
/**
|
||||
getText(padID, [rev]) returns the text of a pad
|
||||
getText(padID, [rev]) returns the text of a pad
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -83,7 +83,7 @@ exports.getText = function(padID, rev, callback)
|
|||
callback = rev;
|
||||
rev = undefined;
|
||||
}
|
||||
|
||||
|
||||
//check if rev is a number
|
||||
if(rev !== undefined && typeof rev != "number")
|
||||
{
|
||||
|
@ -98,26 +98,26 @@ exports.getText = function(padID, rev, callback)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ensure this is not a negativ number
|
||||
if(rev !== undefined && rev < 0)
|
||||
{
|
||||
callback(new customError("rev is a negativ number","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//ensure this is not a float value
|
||||
if(rev !== undefined && !is_int(rev))
|
||||
{
|
||||
callback(new customError("rev is a float value","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//the client asked for a special revision
|
||||
if(rev !== undefined)
|
||||
{
|
||||
|
@ -127,14 +127,14 @@ exports.getText = function(padID, rev, callback)
|
|||
callback(new customError("rev is higher than the head revision of the pad","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//get the text of this revision
|
||||
pad.getInternalRevisionAText(rev, function(err, atext)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
data = {text: atext.text};
|
||||
|
||||
|
||||
callback(null, data);
|
||||
})
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ exports.getText = function(padID, rev, callback)
|
|||
}
|
||||
|
||||
/**
|
||||
setText(padID, text) sets the text of a pad
|
||||
setText(padID, text) sets the text of a pad
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -156,7 +156,7 @@ Example returns:
|
|||
{code: 1, message:"text too long", data: null}
|
||||
*/
|
||||
exports.setText = function(padID, text, callback)
|
||||
{
|
||||
{
|
||||
//text is required
|
||||
if(typeof text != "string")
|
||||
{
|
||||
|
@ -168,17 +168,17 @@ exports.setText = function(padID, text, callback)
|
|||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//set the text
|
||||
pad.setText(text);
|
||||
|
||||
|
||||
//update the clients on the pad
|
||||
padMessageHandler.updatePadClients(pad, callback);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
getHTML(padID, [rev]) returns the html of a pad
|
||||
getHTML(padID, [rev]) returns the html of a pad
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -190,7 +190,7 @@ exports.getHTML = function(padID, rev, callback)
|
|||
if(typeof rev == "function")
|
||||
{
|
||||
callback = rev;
|
||||
rev = undefined;
|
||||
rev = undefined;
|
||||
}
|
||||
|
||||
if (rev !== undefined && typeof rev != "number")
|
||||
|
@ -221,7 +221,7 @@ exports.getHTML = function(padID, rev, callback)
|
|||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//the client asked for a special revision
|
||||
if(rev !== undefined)
|
||||
{
|
||||
|
@ -231,8 +231,8 @@ exports.getHTML = function(padID, rev, callback)
|
|||
callback(new customError("rev is higher than the head revision of the pad","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//get the html of this revision
|
||||
|
||||
//get the html of this revision
|
||||
exportHtml.getPadHTML(pad, rev, function(err, html)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
@ -246,9 +246,9 @@ exports.getHTML = function(padID, rev, callback)
|
|||
exportHtml.getPadHTML(pad, undefined, function (err, html)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
data = {html: html};
|
||||
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ exports.setHTML = function(padID, html, callback)
|
|||
/*****************/
|
||||
|
||||
/**
|
||||
getRevisionsCount(padID) returns the number of revisions of this pad
|
||||
getRevisionsCount(padID) returns the number of revisions of this pad
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -289,7 +289,7 @@ exports.getRevisionsCount = function(padID, callback)
|
|||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
callback(null, {revisions: pad.getHeadRevisionNumber()});
|
||||
});
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ exports.getLastEdited = function(padID, callback)
|
|||
}
|
||||
|
||||
/**
|
||||
createPad(padName [, text]) creates a new pad in this group
|
||||
createPad(padName [, text]) creates a new pad in this group
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -324,14 +324,14 @@ Example returns:
|
|||
{code: 1, message:"pad does already exist", data: null}
|
||||
*/
|
||||
exports.createPad = function(padID, text, callback)
|
||||
{
|
||||
{
|
||||
//ensure there is no $ in the padID
|
||||
if(padID && padID.indexOf("$") != -1)
|
||||
{
|
||||
callback(new customError("createPad can't create group pads","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//create pad
|
||||
getPadSafe(padID, false, text, function(err)
|
||||
{
|
||||
|
@ -341,7 +341,7 @@ exports.createPad = function(padID, text, callback)
|
|||
}
|
||||
|
||||
/**
|
||||
deletePad(padID) deletes a pad
|
||||
deletePad(padID) deletes a pad
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -353,13 +353,13 @@ exports.deletePad = function(padID, callback)
|
|||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
pad.remove(callback);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
getReadOnlyLink(padID) returns the read only link of a pad
|
||||
getReadOnlyLink(padID) returns the read only link of a pad
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -372,7 +372,7 @@ exports.getReadOnlyID = function(padID, callback)
|
|||
getPadSafe(padID, true, function(err)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//get the readonlyId
|
||||
readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId)
|
||||
{
|
||||
|
@ -383,7 +383,7 @@ exports.getReadOnlyID = function(padID, callback)
|
|||
}
|
||||
|
||||
/**
|
||||
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
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -403,20 +403,20 @@ exports.setPublicStatus = function(padID, publicStatus, callback)
|
|||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//convert string to boolean
|
||||
if(typeof publicStatus == "string")
|
||||
publicStatus = publicStatus == "true" ? true : false;
|
||||
|
||||
|
||||
//set the password
|
||||
pad.setPublicStatus(publicStatus);
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
getPublicStatus(padID) return true of false
|
||||
getPublicStatus(padID) return true of false
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -431,18 +431,18 @@ exports.getPublicStatus = function(padID, callback)
|
|||
callback(new customError("You can only get/set the publicStatus of pads that belong to a group","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
callback(null, {publicStatus: pad.getPublicStatus()});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
setPassword(padID, password) returns ok or a error message
|
||||
setPassword(padID, password) returns ok or a error message
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -457,21 +457,21 @@ exports.setPassword = function(padID, password, callback)
|
|||
callback(new customError("You can only get/set the password of pads that belong to a group","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//set the password
|
||||
pad.setPassword(password == "" ? null : password);
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
isPasswordProtected(padID) returns true or false
|
||||
isPasswordProtected(padID) returns true or false
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -491,13 +491,13 @@ exports.isPasswordProtected = function(padID, callback)
|
|||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
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
|
||||
|
||||
Example returns:
|
||||
|
||||
|
@ -510,7 +510,7 @@ exports.listAuthorsOfPad = function(padID, callback)
|
|||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
callback(null, {authorIDs: pad.getAllAuthors()});
|
||||
});
|
||||
}
|
||||
|
@ -555,7 +555,7 @@ exports.sendClientsMessage = function (padID, msg, callback) {
|
|||
|
||||
//checks if a number is an int
|
||||
function is_int(value)
|
||||
{
|
||||
{
|
||||
return (parseFloat(value) == parseInt(value)) && !isNaN(value)
|
||||
}
|
||||
|
||||
|
@ -574,19 +574,19 @@ function getPadSafe(padID, shouldExist, text, callback)
|
|||
callback(new customError("padID is not a string","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//check if the padID maches the requirements
|
||||
if(!padManager.isValidPadId(padID))
|
||||
{
|
||||
callback(new customError("padID did not match requirements","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//check if the pad exists
|
||||
padManager.doesPadExists(padID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//does not exist, but should
|
||||
if(exists == false && shouldExist == true)
|
||||
{
|
||||
|
|
|
@ -38,9 +38,9 @@ exports.doesAuthorExists = function (authorID, callback)
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the AuthorID for a token.
|
||||
* @param {String} token The token
|
||||
* @param {Function} callback callback (err, author)
|
||||
* Returns the AuthorID for a token.
|
||||
* @param {String} token The token
|
||||
* @param {Function} callback callback (err, author)
|
||||
*/
|
||||
exports.getAuthor4Token = function (token, callback)
|
||||
{
|
||||
|
@ -53,21 +53,21 @@ exports.getAuthor4Token = function (token, callback)
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the AuthorID for a mapper.
|
||||
* Returns the AuthorID for a mapper.
|
||||
* @param {String} token The mapper
|
||||
* @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)
|
||||
{
|
||||
mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//set the name of this author
|
||||
if(name)
|
||||
exports.setAuthorName(author.authorID, name);
|
||||
|
||||
|
||||
//return the authorID
|
||||
callback(null, author);
|
||||
});
|
||||
|
@ -76,27 +76,27 @@ exports.createAuthorIfNotExistsFor = function (authorMapper, name, callback)
|
|||
/**
|
||||
* Returns the AuthorID for a mapper. We can map using a mapperkey,
|
||||
* so far this is token2author and mapper2author
|
||||
* @param {String} mapperkey The database key name for this mapper
|
||||
* @param {String} mapperkey The database key name for this mapper
|
||||
* @param {String} mapper The mapper
|
||||
* @param {Function} callback callback (err, author)
|
||||
* @param {Function} callback callback (err, author)
|
||||
*/
|
||||
function mapAuthorWithDBKey (mapperkey, mapper, callback)
|
||||
{
|
||||
{
|
||||
//try to map to an author
|
||||
db.get(mapperkey + ":" + mapper, function (err, author)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//there is no author with this mapper, so create one
|
||||
if(author == null)
|
||||
{
|
||||
exports.createAuthor(null, function(err, author)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//create the token2author relation
|
||||
db.set(mapperkey + ":" + mapper, author.authorID);
|
||||
|
||||
|
||||
//return the author
|
||||
callback(null, author);
|
||||
});
|
||||
|
@ -106,7 +106,7 @@ function mapAuthorWithDBKey (mapperkey, mapper, callback)
|
|||
{
|
||||
//update the timestamp of this author
|
||||
db.setSub("globalAuthor:" + author, ["timestamp"], new Date().getTime());
|
||||
|
||||
|
||||
//return the author
|
||||
callback(null, {authorID: author});
|
||||
}
|
||||
|
@ -114,20 +114,20 @@ function mapAuthorWithDBKey (mapperkey, mapper, callback)
|
|||
}
|
||||
|
||||
/**
|
||||
* Internal function that creates the database entry for an author
|
||||
* @param {String} name The name of the author
|
||||
* Internal function that creates the database entry for an author
|
||||
* @param {String} name The name of the author
|
||||
*/
|
||||
exports.createAuthor = function(name, callback)
|
||||
{
|
||||
//create the new author name
|
||||
var author = "a." + randomString(16);
|
||||
|
||||
|
||||
//create the globalAuthors db entry
|
||||
var authorObj = {"colorId" : Math.floor(Math.random()*32), "name": name, "timestamp": new Date().getTime()};
|
||||
|
||||
|
||||
//set the global author db entry
|
||||
db.set("globalAuthor:" + author, authorObj);
|
||||
|
||||
|
||||
callback(null, {authorID: author});
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ exports.listPadsOfAuthor = function (authorID, callback)
|
|||
}
|
||||
//everything is fine, return the pad IDs
|
||||
else
|
||||
{
|
||||
{
|
||||
var pads = [];
|
||||
if(author.padIDs != null)
|
||||
{
|
||||
|
@ -234,16 +234,16 @@ exports.addPad = function (authorID, padID)
|
|||
{
|
||||
if(ERR(err)) return;
|
||||
if(author == null) return;
|
||||
|
||||
|
||||
//the entry doesn't exist so far, let's create it
|
||||
if(author.padIDs == null)
|
||||
{
|
||||
author.padIDs = {};
|
||||
}
|
||||
|
||||
|
||||
//add the entry for this pad
|
||||
author.padIDs[padID] = 1;// anything, because value is not used
|
||||
|
||||
|
||||
//save the new element back
|
||||
db.set("globalAuthor:" + authorID, author);
|
||||
});
|
||||
|
@ -260,11 +260,11 @@ exports.removePad = function (authorID, padID)
|
|||
{
|
||||
if(ERR(err)) return;
|
||||
if(author == null) return;
|
||||
|
||||
|
||||
if(author.padIDs != null)
|
||||
{
|
||||
//remove pad from author
|
||||
delete author.padIDs[padID];
|
||||
delete author.padIDs[padID];
|
||||
db.set("globalAuthor:" + authorID, author);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* The DB Module provides a database initalized with the settings
|
||||
* The DB Module provides a database initalized with the settings
|
||||
* provided by the settings module
|
||||
*/
|
||||
|
||||
|
@ -33,14 +33,14 @@ exports.db = null;
|
|||
|
||||
/**
|
||||
* Initalizes the database with the settings provided by the settings module
|
||||
* @param {Function} callback
|
||||
* @param {Function} callback
|
||||
*/
|
||||
exports.init = function(callback)
|
||||
{
|
||||
//initalize the database async
|
||||
db.init(function(err)
|
||||
{
|
||||
//there was an error while initializing the database, output it and stop
|
||||
//there was an error while initializing the database, output it and stop
|
||||
if(err)
|
||||
{
|
||||
console.error("ERROR: Problem while initalizing the database");
|
||||
|
@ -50,7 +50,7 @@ exports.init = function(callback)
|
|||
//everything ok
|
||||
else
|
||||
{
|
||||
exports.db = db;
|
||||
exports.db = db;
|
||||
callback(null);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
|
@ -30,13 +30,13 @@ var sessionManager = require("./SessionManager");
|
|||
exports.listAllGroups = function(callback) {
|
||||
db.get("groups", function (err, groups) {
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
// there are no groups
|
||||
if(groups == null) {
|
||||
callback(null, {groupIDs: []});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var groupIDs = [];
|
||||
for ( var groupID in groups ) {
|
||||
groupIDs.push(groupID);
|
||||
|
@ -44,20 +44,20 @@ exports.listAllGroups = function(callback) {
|
|||
callback(null, {groupIDs: groupIDs});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
exports.deleteGroup = function(groupID, callback)
|
||||
{
|
||||
var group;
|
||||
|
||||
async.series([
|
||||
//ensure group exists
|
||||
//ensure group exists
|
||||
function (callback)
|
||||
{
|
||||
//try to get the group entry
|
||||
db.get("group:" + groupID, function (err, _group)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//group does not exist
|
||||
if(_group == null)
|
||||
{
|
||||
|
@ -80,14 +80,14 @@ exports.deleteGroup = function(groupID, callback)
|
|||
{
|
||||
padIDs.push(i);
|
||||
}
|
||||
|
||||
//loop trough all pads and delete them
|
||||
|
||||
//loop trough all pads and delete them
|
||||
async.forEach(padIDs, function(padID, callback)
|
||||
{
|
||||
padManager.getPad(padID, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
pad.remove(callback);
|
||||
});
|
||||
}, callback);
|
||||
|
@ -99,18 +99,18 @@ exports.deleteGroup = function(groupID, callback)
|
|||
db.get("group2sessions:" + groupID, function (err, group2sessions)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//skip if there is no group2sessions entry
|
||||
if(group2sessions == null) {callback(); return}
|
||||
|
||||
|
||||
//collect all sessions in an array, that allows us to use async.forEach
|
||||
var sessions = [];
|
||||
for(var i in group2sessions.sessionsIDs)
|
||||
{
|
||||
sessions.push(i);
|
||||
}
|
||||
|
||||
//loop trough all sessions and delete them
|
||||
|
||||
//loop trough all sessions and delete them
|
||||
async.forEach(sessions, function(session, callback)
|
||||
{
|
||||
sessionManager.deleteSession(session, callback);
|
||||
|
@ -138,7 +138,7 @@ exports.deleteGroup = function(groupID, callback)
|
|||
}
|
||||
|
||||
groups.splice(groups.indexOf(groupID), 1);
|
||||
|
||||
|
||||
// store empty groupe list
|
||||
if(groups.length == 0) {
|
||||
db.set("groups", {});
|
||||
|
@ -163,7 +163,7 @@ exports.deleteGroup = function(groupID, callback)
|
|||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
exports.doesGroupExist = function(groupID, callback)
|
||||
{
|
||||
//try to get the group entry
|
||||
|
@ -178,17 +178,17 @@ exports.createGroup = function(callback)
|
|||
{
|
||||
//search for non existing groupID
|
||||
var groupID = "g." + randomString(16);
|
||||
|
||||
|
||||
//create the group
|
||||
db.set("group:" + groupID, {pads: {}});
|
||||
|
||||
|
||||
//list the group
|
||||
exports.listAllGroups(function(err, groups) {
|
||||
if(ERR(err, callback)) return;
|
||||
groups = groups? groups.groupIDs : [];
|
||||
|
||||
|
||||
groups.push(groupID);
|
||||
|
||||
|
||||
// regenerate group list
|
||||
var newGroups = {};
|
||||
async.forEach(groups, function(group, cb) {
|
||||
|
@ -209,22 +209,22 @@ exports.createGroupIfNotExistsFor = function(groupMapper, callback)
|
|||
callback(new customError("groupMapper is no string","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//try to get a group for this mapper
|
||||
db.get("mapper2group:"+groupMapper, function(err, groupID)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//there is no group for this mapper, let's create a group
|
||||
if(groupID == null)
|
||||
{
|
||||
exports.createGroup(function(err, responseObj)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//create the mapper entry for this group
|
||||
db.set("mapper2group:"+groupMapper, responseObj.groupID);
|
||||
|
||||
|
||||
callback(null, responseObj);
|
||||
});
|
||||
}
|
||||
|
@ -243,13 +243,13 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
|||
var padID = groupID + "$" + padName;
|
||||
|
||||
async.series([
|
||||
//ensure group exists
|
||||
//ensure group exists
|
||||
function (callback)
|
||||
{
|
||||
exports.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//group does not exist
|
||||
if(exists == false)
|
||||
{
|
||||
|
@ -268,7 +268,7 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
|||
padManager.doesPadExists(padID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//pad exists already
|
||||
if(exists == true)
|
||||
{
|
||||
|
@ -308,7 +308,7 @@ exports.listPads = function(groupID, callback)
|
|||
exports.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//group does not exist
|
||||
if(exists == false)
|
||||
{
|
||||
|
|
|
@ -83,33 +83,33 @@ Pad.prototype.appendRevision = function appendRevision(aChangeset, author) {
|
|||
|
||||
db.set("pad:"+this.id+":revs:"+newRev, newRevData);
|
||||
this.saveToDatabase();
|
||||
|
||||
|
||||
// set the author to pad
|
||||
if(author)
|
||||
authorManager.addPad(author, this.id);
|
||||
|
||||
|
||||
if (this.head == 0) {
|
||||
hooks.callAll("padCreate", {'pad':this});
|
||||
} else {
|
||||
hooks.callAll("padUpdate", {'pad':this});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//save all attributes to the database
|
||||
Pad.prototype.saveToDatabase = function saveToDatabase(){
|
||||
var dbObject = {};
|
||||
|
||||
|
||||
for(var attr in this){
|
||||
if(typeof this[attr] === "function") continue;
|
||||
if(attributeBlackList.indexOf(attr) !== -1) continue;
|
||||
|
||||
|
||||
dbObject[attr] = this[attr];
|
||||
|
||||
|
||||
if(jsonableList.indexOf(attr) !== -1){
|
||||
dbObject[attr] = dbObject[attr].toJsonable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
db.set("pad:"+this.id, dbObject);
|
||||
}
|
||||
|
||||
|
@ -510,7 +510,7 @@ Pad.prototype.addSavedRevision = function addSavedRevision(revNum, savedById, la
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//build the saved revision object
|
||||
var savedRevision = {};
|
||||
savedRevision.revNum = revNum;
|
||||
|
@ -518,7 +518,7 @@ Pad.prototype.addSavedRevision = function addSavedRevision(revNum, savedById, la
|
|||
savedRevision.label = label || "Revision " + revNum;
|
||||
savedRevision.timestamp = new Date().getTime();
|
||||
savedRevision.id = randomString(10);
|
||||
|
||||
|
||||
//save this new saved revision
|
||||
this.savedRevisions.push(savedRevision);
|
||||
this.saveToDatabase();
|
||||
|
|
|
@ -23,7 +23,7 @@ var customError = require("../utils/customError");
|
|||
var Pad = require("../db/Pad").Pad;
|
||||
var db = require("./DB").db;
|
||||
|
||||
/**
|
||||
/**
|
||||
* An Object containing all known Pads. Provides "get" and "set" functions,
|
||||
* which should be used instead of indexing with brackets. These prepend a
|
||||
* colon to the key, to avoid conflicting with built-in Object methods or with
|
||||
|
@ -50,24 +50,24 @@ var padIdTransforms = [
|
|||
/**
|
||||
* Returns a Pad Object with the callback
|
||||
* @param id A String with the id of the pad
|
||||
* @param {Function} callback
|
||||
* @param {Function} callback
|
||||
*/
|
||||
exports.getPad = function(id, text, callback)
|
||||
{
|
||||
{
|
||||
//check if this is a valid padId
|
||||
if(!exports.isValidPadId(id))
|
||||
{
|
||||
callback(new customError(id + " is not a valid padId","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//make text an optional parameter
|
||||
if(typeof text == "function")
|
||||
{
|
||||
callback = text;
|
||||
text = null;
|
||||
}
|
||||
|
||||
|
||||
//check if this is a valid text
|
||||
if(text != null)
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ exports.getPad = function(id, text, callback)
|
|||
callback(new customError("text is not a string","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//check if text is less than 100k chars
|
||||
if(text.length > 100000)
|
||||
{
|
||||
|
@ -85,9 +85,9 @@ exports.getPad = function(id, text, callback)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var pad = globalPads.get(id);
|
||||
|
||||
|
||||
//return pad if its already loaded
|
||||
if(pad != null)
|
||||
{
|
||||
|
@ -97,12 +97,12 @@ exports.getPad = function(id, text, callback)
|
|||
else
|
||||
{
|
||||
pad = new Pad(id);
|
||||
|
||||
|
||||
//initalize the pad
|
||||
pad.init(text, function(err)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
globalPads.set(id, pad);
|
||||
callback(null, pad);
|
||||
});
|
||||
|
@ -120,7 +120,7 @@ exports.doesPadExists = function(padId, callback)
|
|||
}
|
||||
else
|
||||
{
|
||||
callback(null, false);
|
||||
callback(null, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
|||
* @param {String} padId the id of the pad
|
||||
*/
|
||||
exports.getReadOnlyId = function (padId, callback)
|
||||
{
|
||||
{
|
||||
var readOnlyId;
|
||||
|
||||
|
||||
async.waterfall([
|
||||
//check if there is a pad2readonly entry
|
||||
function(callback)
|
||||
|
@ -44,7 +44,7 @@ exports.getReadOnlyId = function (padId, callback)
|
|||
if(dbReadOnlyId == null)
|
||||
{
|
||||
readOnlyId = "r." + randomString(16);
|
||||
|
||||
|
||||
db.set("pad2readonly:" + padId, readOnlyId);
|
||||
db.set("readonly2pad:" + readOnlyId, padId);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ exports.getReadOnlyId = function (padId, callback)
|
|||
{
|
||||
readOnlyId = dbReadOnlyId;
|
||||
}
|
||||
|
||||
|
||||
callback();
|
||||
}
|
||||
], function(err)
|
||||
|
|
|
@ -33,11 +33,11 @@ var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
|||
* @param padID the pad the user wants to access
|
||||
* @param sesssionID the session the user has (set via api)
|
||||
* @param token the token of the author (randomly generated at client side, used for public pads)
|
||||
* @param password the password the user has given to access this pad, can be null
|
||||
* @param password the password the user has given to access this pad, can be null
|
||||
* @param callback will be called with (err, {accessStatus: grant|deny|wrongPassword|needPassword, authorID: a.xxxxxx})
|
||||
*/
|
||||
*/
|
||||
exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
||||
{
|
||||
{
|
||||
var statusObject;
|
||||
|
||||
// a valid session is required (api-only mode)
|
||||
|
@ -60,7 +60,7 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
authorManager.getAuthor4Token(token, function(err, author)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
// assume user has access
|
||||
statusObject = {accessStatus: "grant", authorID: author};
|
||||
// user can't create pads
|
||||
|
@ -70,7 +70,7 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
padManager.doesPadExists(padID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
// pad doesn't exist - user can't have access
|
||||
if(!exists) statusObject.accessStatus = "deny";
|
||||
// grant or deny access, with author of token
|
||||
|
@ -84,12 +84,12 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
callback(null, statusObject);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
//don't continue
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var groupID = padID.split("$")[0];
|
||||
var padExists = false;
|
||||
var validSession = false;
|
||||
|
@ -100,7 +100,7 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
var passwordStatus = password == null ? "notGiven" : "wrong"; // notGiven, correct, wrong
|
||||
|
||||
async.series([
|
||||
//get basic informations from the database
|
||||
//get basic informations from the database
|
||||
function(callback)
|
||||
{
|
||||
async.parallel([
|
||||
|
@ -121,27 +121,27 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var sessionIDs = sessionCookie.split(',');
|
||||
async.forEach(sessionIDs, function(sessionID, callback) {
|
||||
sessionManager.getSessionInfo(sessionID, function(err, sessionInfo) {
|
||||
//skip session if it doesn't exist
|
||||
if(err && err.message == "sessionID does not exist") return;
|
||||
|
||||
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
var now = Math.floor(new Date().getTime()/1000);
|
||||
|
||||
|
||||
//is it for this group?
|
||||
if(sessionInfo.groupID != groupID) return;
|
||||
|
||||
|
||||
//is validUntil still ok?
|
||||
if(sessionInfo.validUntil <= now) return;
|
||||
|
||||
|
||||
// There is a valid session
|
||||
validSession = true;
|
||||
sessionAuthor = sessionInfo.authorID;
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
}, callback);
|
||||
|
@ -163,28 +163,28 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
function(callback)
|
||||
{
|
||||
//skip this if the pad doesn't exists
|
||||
if(padExists == false)
|
||||
if(padExists == false)
|
||||
{
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
padManager.getPad(padID, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//is it a public pad?
|
||||
isPublic = pad.getPublicStatus();
|
||||
|
||||
|
||||
//is it password protected?
|
||||
isPasswordProtected = pad.isPasswordProtected();
|
||||
|
||||
|
||||
//is password correct?
|
||||
if(isPasswordProtected && password && pad.isCorrectPassword(password))
|
||||
{
|
||||
passwordStatus = "correct";
|
||||
}
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
@ -221,7 +221,7 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
{
|
||||
throw new Error("Ops, something wrong happend");
|
||||
}
|
||||
}
|
||||
}
|
||||
//- a valid session for this group avaible but pad doesn't exists
|
||||
else if(validSession && !padExists)
|
||||
{
|
||||
|
@ -245,7 +245,7 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
//--> grant access, with author of token
|
||||
statusObject = {accessStatus: "grant", authorID: tokenAuthor};
|
||||
}
|
||||
//- its public and the pad is password protected but wrong password given
|
||||
//- its public and the pad is password protected but wrong password given
|
||||
else if(isPublic && isPasswordProtected && passwordStatus == "wrong")
|
||||
{
|
||||
//--> deny access, ask for new password and tell them that the password is wrong
|
||||
|
@ -267,14 +267,14 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
|
|||
{
|
||||
throw new Error("Ops, something wrong happend");
|
||||
}
|
||||
}
|
||||
}
|
||||
// there is no valid session avaiable AND pad doesn't exists
|
||||
else
|
||||
{
|
||||
//--> deny access
|
||||
statusObject = {accessStatus: "deny"};
|
||||
}
|
||||
|
||||
|
||||
callback();
|
||||
}
|
||||
], function(err)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
|
@ -26,7 +26,7 @@ var db = require("./DB").db;
|
|||
var async = require("async");
|
||||
var groupMangager = require("./GroupManager");
|
||||
var authorMangager = require("./AuthorManager");
|
||||
|
||||
|
||||
exports.doesSessionExist = function(sessionID, callback)
|
||||
{
|
||||
//check if the database entry of this session exists
|
||||
|
@ -36,7 +36,7 @@ exports.doesSessionExist = function(sessionID, callback)
|
|||
callback(null, session != null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new session between an author and a group
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
groupMangager.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//group does not exist
|
||||
if(exists == false)
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
authorMangager.doesAuthorExists(authorID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//author does not exist
|
||||
if(exists == false)
|
||||
{
|
||||
|
@ -100,34 +100,34 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ensure this is not a negativ number
|
||||
if(validUntil < 0)
|
||||
{
|
||||
callback(new customError("validUntil is a negativ number","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//ensure this is not a float value
|
||||
if(!is_int(validUntil))
|
||||
{
|
||||
callback(new customError("validUntil is a float value","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//check if validUntil is in the future
|
||||
if(Math.floor(new Date().getTime()/1000) > validUntil)
|
||||
{
|
||||
callback(new customError("validUntil is in the past","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//generate sessionID
|
||||
sessionID = "s." + randomString(16);
|
||||
|
||||
|
||||
//set the session into the database
|
||||
db.set("session:" + sessionID, {"groupID": groupID, "authorID": authorID, "validUntil": validUntil});
|
||||
|
||||
|
||||
callback();
|
||||
},
|
||||
//set the group2sessions entry
|
||||
|
@ -137,19 +137,19 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
db.get("group2sessions:" + groupID, function(err, group2sessions)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//the entry doesn't exist so far, let's create it
|
||||
if(group2sessions == null || group2sessions.sessionIDs == null)
|
||||
{
|
||||
group2sessions = {sessionIDs : {}};
|
||||
}
|
||||
|
||||
|
||||
//add the entry for this session
|
||||
group2sessions.sessionIDs[sessionID] = 1;
|
||||
|
||||
|
||||
//save the new element back
|
||||
db.set("group2sessions:" + groupID, group2sessions);
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
@ -160,26 +160,26 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
db.get("author2sessions:" + authorID, function(err, author2sessions)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//the entry doesn't exist so far, let's create it
|
||||
if(author2sessions == null || author2sessions.sessionIDs == null)
|
||||
{
|
||||
author2sessions = {sessionIDs : {}};
|
||||
}
|
||||
|
||||
|
||||
//add the entry for this session
|
||||
author2sessions.sessionIDs[sessionID] = 1;
|
||||
|
||||
|
||||
//save the new element back
|
||||
db.set("author2sessions:" + authorID, author2sessions);
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
], function(err)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//return error and sessionID
|
||||
callback(null, {sessionID: sessionID});
|
||||
})
|
||||
|
@ -191,7 +191,7 @@ exports.getSessionInfo = function(sessionID, callback)
|
|||
db.get("session:" + sessionID, function (err, session)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//session does not exists
|
||||
if(session == null)
|
||||
{
|
||||
|
@ -220,7 +220,7 @@ exports.deleteSession = function(sessionID, callback)
|
|||
db.get("session:" + sessionID, function (err, session)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//session does not exists
|
||||
if(session == null)
|
||||
{
|
||||
|
@ -231,7 +231,7 @@ exports.deleteSession = function(sessionID, callback)
|
|||
{
|
||||
authorID = session.authorID;
|
||||
groupID = session.groupID;
|
||||
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
@ -261,15 +261,15 @@ exports.deleteSession = function(sessionID, callback)
|
|||
{
|
||||
//remove the session
|
||||
db.remove("session:" + sessionID);
|
||||
|
||||
|
||||
//remove session from group2sessions
|
||||
delete group2sessions.sessionIDs[sessionID];
|
||||
db.set("group2sessions:" + groupID, group2sessions);
|
||||
|
||||
|
||||
//remove session from author2sessions
|
||||
delete author2sessions.sessionIDs[sessionID];
|
||||
db.set("author2sessions:" + authorID, author2sessions);
|
||||
|
||||
|
||||
callback();
|
||||
}
|
||||
], function(err)
|
||||
|
@ -284,7 +284,7 @@ exports.listSessionsOfGroup = function(groupID, callback)
|
|||
groupMangager.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//group does not exist
|
||||
if(exists == false)
|
||||
{
|
||||
|
@ -299,11 +299,11 @@ exports.listSessionsOfGroup = function(groupID, callback)
|
|||
}
|
||||
|
||||
exports.listSessionsOfAuthor = function(authorID, callback)
|
||||
{
|
||||
{
|
||||
authorMangager.doesAuthorExists(authorID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
|
||||
//group does not exist
|
||||
if(exists == false)
|
||||
{
|
||||
|
@ -334,14 +334,14 @@ function listSessionsWithDBKey (dbkey, callback)
|
|||
});
|
||||
},
|
||||
function(callback)
|
||||
{
|
||||
{
|
||||
//collect all sessionIDs in an arrary
|
||||
var sessionIDs = [];
|
||||
for (var i in sessions)
|
||||
{
|
||||
sessionIDs.push(i);
|
||||
}
|
||||
|
||||
|
||||
//foreach trough the sessions and get the sessioninfos
|
||||
async.forEach(sessionIDs, function(sessionID, callback)
|
||||
{
|
||||
|
@ -362,6 +362,6 @@ function listSessionsWithDBKey (dbkey, callback)
|
|||
|
||||
//checks if a number is an int
|
||||
function is_int(value)
|
||||
{
|
||||
{
|
||||
return (parseFloat(value) == parseInt(value)) && !isNaN(value)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue