mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-08 16:05:05 -04:00
merge with upstream. Fixed confict in pad.html
This commit is contained in:
parent
3248ca4cbb
commit
254046454d
91 changed files with 1674 additions and 1363 deletions
154
node/db/API.js
154
node/db/API.js
|
@ -18,6 +18,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
var padManager = require("./PadManager");
|
||||
var padMessageHandler = require("../handler/PadMessageHandler");
|
||||
var readOnlyManager = require("./ReadOnlyManager");
|
||||
|
@ -87,7 +89,7 @@ exports.getText = function(padID, rev, callback)
|
|||
}
|
||||
else
|
||||
{
|
||||
callback({stop: "rev is not a number"});
|
||||
callback(new customError("rev is not a number", "apierror"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -95,25 +97,21 @@ exports.getText = function(padID, rev, callback)
|
|||
//ensure this is not a negativ number
|
||||
if(rev !== undefined && rev < 0)
|
||||
{
|
||||
callback({stop: "rev is a negativ number"});
|
||||
callback(new customError("rev is a negativ number","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//ensure this is not a float value
|
||||
if(rev !== undefined && !is_int(rev))
|
||||
{
|
||||
callback({stop: "rev is a float value"});
|
||||
callback(new customError("rev is a float value","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//the client asked for a special revision
|
||||
if(rev !== undefined)
|
||||
|
@ -121,19 +119,18 @@ exports.getText = function(padID, rev, callback)
|
|||
//check if this is a valid revision
|
||||
if(rev > pad.getHeadRevisionNumber())
|
||||
{
|
||||
callback({stop: "rev is higher than the head revision of the pad"});
|
||||
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)
|
||||
{
|
||||
data = {text: atext.text};
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
callback(err, data);
|
||||
data = {text: atext.text};
|
||||
|
||||
callback(null, data);
|
||||
})
|
||||
}
|
||||
//the client wants the latest text, lets return it to him
|
||||
|
@ -158,11 +155,7 @@ exports.setText = function(padID, text, callback)
|
|||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//set the text
|
||||
pad.setText(text);
|
||||
|
@ -196,30 +189,26 @@ exports.getHTML = function(padID, rev, callback)
|
|||
}
|
||||
else
|
||||
{
|
||||
callback({stop: "rev is not a number"});
|
||||
callback(new customError("rev is not a number","apierror"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(rev !== undefined && rev < 0)
|
||||
{
|
||||
callback({stop: "rev is a negative number"});
|
||||
callback(new customError("rev is a negative number","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(rev !== undefined && !is_int(rev))
|
||||
{
|
||||
callback({stop: "rev is a float value"});
|
||||
callback(new customError("rev is a float value","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//the client asked for a special revision
|
||||
if(rev !== undefined)
|
||||
|
@ -227,18 +216,16 @@ exports.getHTML = function(padID, rev, callback)
|
|||
//check if this is a valid revision
|
||||
if(rev > pad.getHeadRevisionNumber())
|
||||
{
|
||||
callback({stop: "rev is higher than the head revision of the pad"});
|
||||
callback(new customError("rev is higher than the head revision of the pad","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//get the html of this revision
|
||||
exportHtml.getPadHTML(pad, rev, function(err, html)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
data = {html: html};
|
||||
}
|
||||
callback(err, data);
|
||||
if(ERR(err, callback)) return;
|
||||
data = {html: html};
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
//the client wants the latest text, lets return it to him
|
||||
|
@ -246,11 +233,11 @@ exports.getHTML = function(padID, rev, callback)
|
|||
{
|
||||
exportHtml.getPadHTML(pad, undefined, function (err, html)
|
||||
{
|
||||
if(!err)
|
||||
{
|
||||
data = {html: html};
|
||||
}
|
||||
callback(err, data);
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
data = {html: html};
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -261,11 +248,7 @@ exports.setHTML = function(padID, html, callback)
|
|||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
// add a new changeset with the new html to the pad
|
||||
importHtml.setPadHTML(pad, cleanText(html));
|
||||
|
@ -293,11 +276,7 @@ exports.getRevisionsCount = function(padID, callback)
|
|||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
callback(null, {revisions: pad.getHeadRevisionNumber()});
|
||||
});
|
||||
|
@ -314,16 +293,17 @@ Example returns:
|
|||
exports.createPad = function(padID, text, callback)
|
||||
{
|
||||
//ensure there is no $ in the padID
|
||||
if(padID.indexOf("$") != -1)
|
||||
if(padID && padID.indexOf("$") != -1)
|
||||
{
|
||||
callback({stop: "createPad can't create group pads"});
|
||||
callback(new customError("createPad can't create group pads","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//create pad
|
||||
getPadSafe(padID, false, text, function(err)
|
||||
{
|
||||
callback(err);
|
||||
if(ERR(err, callback)) return;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -339,11 +319,7 @@ exports.deletePad = function(padID, callback)
|
|||
{
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
pad.remove(callback);
|
||||
});
|
||||
|
@ -362,16 +338,13 @@ exports.getReadOnlyID = 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)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//get the readonlyId
|
||||
readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId)
|
||||
{
|
||||
callback(err, {readOnlyID: readOnlyId});
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, {readOnlyID: readOnlyId});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -387,20 +360,16 @@ Example returns:
|
|||
exports.setPublicStatus = function(padID, publicStatus, callback)
|
||||
{
|
||||
//ensure this is a group pad
|
||||
if(padID.indexOf("$") == -1)
|
||||
if(padID && padID.indexOf("$") == -1)
|
||||
{
|
||||
callback({stop: "You can only get/set the publicStatus of pads that belong to a group"});
|
||||
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)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//convert string to boolean
|
||||
if(typeof publicStatus == "string")
|
||||
|
@ -424,20 +393,16 @@ Example returns:
|
|||
exports.getPublicStatus = function(padID, callback)
|
||||
{
|
||||
//ensure this is a group pad
|
||||
if(padID.indexOf("$") == -1)
|
||||
if(padID && padID.indexOf("$") == -1)
|
||||
{
|
||||
callback({stop: "You can only get/set the publicStatus of pads that belong to a group"});
|
||||
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)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
callback(null, {publicStatus: pad.getPublicStatus()});
|
||||
});
|
||||
|
@ -454,20 +419,16 @@ Example returns:
|
|||
exports.setPassword = function(padID, password, callback)
|
||||
{
|
||||
//ensure this is a group pad
|
||||
if(padID.indexOf("$") == -1)
|
||||
if(padID && padID.indexOf("$") == -1)
|
||||
{
|
||||
callback({stop: "You can only get/set the password of pads that belong to a group"});
|
||||
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)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//set the password
|
||||
pad.setPassword(password);
|
||||
|
@ -487,20 +448,16 @@ Example returns:
|
|||
exports.isPasswordProtected = function(padID, callback)
|
||||
{
|
||||
//ensure this is a group pad
|
||||
if(padID.indexOf("$") == -1)
|
||||
if(padID && padID.indexOf("$") == -1)
|
||||
{
|
||||
callback({stop: "You can only get/set the password of pads that belong to a group"});
|
||||
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)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
|
||||
});
|
||||
|
@ -528,34 +485,31 @@ function getPadSafe(padID, shouldExist, text, callback)
|
|||
//check if padID is a string
|
||||
if(typeof padID != "string")
|
||||
{
|
||||
callback({stop: "padID is not a string"});
|
||||
callback(new customError("padID is not a string","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//check if the padID maches the requirements
|
||||
if(!padManager.isValidPadId(padID))
|
||||
{
|
||||
callback({stop: "padID did not match requirements"});
|
||||
callback(new customError("padID did not match requirements","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//check if the pad exists
|
||||
padManager.doesPadExists(padID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//does not exist, but should
|
||||
else if(exists == false && shouldExist == true)
|
||||
if(exists == false && shouldExist == true)
|
||||
{
|
||||
callback({stop: "padID does not exist"});
|
||||
callback(new customError("padID does not exist","apierror"));
|
||||
}
|
||||
//does exists, but shouldn't
|
||||
else if(exists == true && shouldExist == false)
|
||||
{
|
||||
callback({stop: "padID does already exist"});
|
||||
callback(new customError("padID does already exist","apierror"));
|
||||
}
|
||||
//pad exists, let's get it
|
||||
else
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
|
||||
|
@ -29,7 +30,8 @@ exports.doesAuthorExists = function (authorID, callback)
|
|||
//check if the database entry of this author exists
|
||||
db.get("globalAuthor:" + authorID, function (err, author)
|
||||
{
|
||||
callback(err, author != null);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, author != null);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -42,8 +44,9 @@ exports.getAuthor4Token = function (token, callback)
|
|||
{
|
||||
mapAuthorWithDBKey("token2author", token, function(err, author)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
//return only the sub value authorID
|
||||
callback(err, author ? author.authorID : author);
|
||||
callback(null, author ? author.authorID : author);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -56,12 +59,7 @@ exports.createAuthorIfNotExistsFor = function (authorMapper, name, callback)
|
|||
{
|
||||
mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author)
|
||||
{
|
||||
//error?
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//set the name of this author
|
||||
if(name)
|
||||
|
@ -84,24 +82,14 @@ function mapAuthorWithDBKey (mapperkey, mapper, callback)
|
|||
//try to map to an author
|
||||
db.get(mapperkey + ":" + mapper, function (err, author)
|
||||
{
|
||||
//error?
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//there is no author with this mapper, so create one
|
||||
if(author == null)
|
||||
{
|
||||
exports.createAuthor(null, function(err, author)
|
||||
{
|
||||
//error?
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//create the token2author relation
|
||||
db.set(mapperkey + ":" + mapper, author.authorID);
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
var padManager = require("./PadManager");
|
||||
|
@ -34,15 +36,12 @@ exports.deleteGroup = function(groupID, callback)
|
|||
//try to get the group entry
|
||||
db.get("group:" + groupID, function (err, _group)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//group does not exist
|
||||
else if(_group == null)
|
||||
if(_group == null)
|
||||
{
|
||||
callback({stop: "groupID does not exist"});
|
||||
callback(new customError("groupID does not exist","apierror"));
|
||||
}
|
||||
//group exists, everything is fine
|
||||
else
|
||||
|
@ -67,7 +66,7 @@ exports.deleteGroup = function(groupID, callback)
|
|||
{
|
||||
padManager.getPad(padID, function(err, pad)
|
||||
{
|
||||
if(err) {callback(err); return}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
pad.remove(callback);
|
||||
});
|
||||
|
@ -79,7 +78,7 @@ exports.deleteGroup = function(groupID, callback)
|
|||
//try to get the group entry
|
||||
db.get("group2sessions:" + groupID, function (err, group2sessions)
|
||||
{
|
||||
if(err) {callback(err); return}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//skip if there is no group2sessions entry
|
||||
if(group2sessions == null) {callback(); return}
|
||||
|
@ -107,7 +106,8 @@ exports.deleteGroup = function(groupID, callback)
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err);
|
||||
if(ERR(err, callback)) return;
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,8 @@ exports.doesGroupExist = function(groupID, callback)
|
|||
//try to get the group entry
|
||||
db.get("group:" + groupID, function (err, group)
|
||||
{
|
||||
callback(err, group != null);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, group != null);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -135,30 +136,21 @@ exports.createGroupIfNotExistsFor = function(groupMapper, callback)
|
|||
//ensure mapper is optional
|
||||
if(typeof groupMapper != "string")
|
||||
{
|
||||
callback({stop: "groupMapper is no string"});
|
||||
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)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
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)
|
||||
{
|
||||
//check for errors
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//create the mapper entry for this group
|
||||
db.set("mapper2group:"+groupMapper, responseObj.groupID);
|
||||
|
@ -169,7 +161,8 @@ exports.createGroupIfNotExistsFor = function(groupMapper, callback)
|
|||
//there is a group for this mapper, let's return it
|
||||
else
|
||||
{
|
||||
callback(err, {groupID: groupID});
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, {groupID: groupID});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -185,15 +178,12 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
|||
{
|
||||
exports.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//group does not exist
|
||||
else if(exists == false)
|
||||
if(exists == false)
|
||||
{
|
||||
callback({stop: "groupID does not exist"});
|
||||
callback(new customError("groupID does not exist","apierror"));
|
||||
}
|
||||
//group exists, everything is fine
|
||||
else
|
||||
|
@ -207,15 +197,12 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
|||
{
|
||||
padManager.doesPadExists(padID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//pad exists already
|
||||
else if(exists == true)
|
||||
if(exists == true)
|
||||
{
|
||||
callback({stop: "padName does already exist"});
|
||||
callback(new customError("padName does already exist","apierror"));
|
||||
}
|
||||
//pad does not exist, everything is fine
|
||||
else
|
||||
|
@ -229,7 +216,8 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
|||
{
|
||||
padManager.getPad(padID, text, function(err)
|
||||
{
|
||||
callback(err);
|
||||
if(ERR(err, callback)) return;
|
||||
callback();
|
||||
});
|
||||
},
|
||||
//create an entry in the group for this pad
|
||||
|
@ -240,7 +228,8 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err, {padID: padID});
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, {padID: padID});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -248,22 +237,20 @@ exports.listPads = function(groupID, callback)
|
|||
{
|
||||
exports.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//group does not exist
|
||||
else if(exists == false)
|
||||
if(exists == false)
|
||||
{
|
||||
callback({stop: "groupID does not exist"});
|
||||
callback(new customError("groupID does not exist","apierror"));
|
||||
}
|
||||
//group exists, let's get the pads
|
||||
else
|
||||
{
|
||||
db.getSub("group:" + groupID, ["pads"], function(err, pads)
|
||||
{
|
||||
callback(err, {padIDs: pads});
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, {padIDs: pads});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
require('joose');
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var Changeset = require("../utils/Changeset");
|
||||
var AttributePoolFactory = require("../utils/AttributePoolFactory");
|
||||
var db = require("./DB").db;
|
||||
|
@ -164,8 +165,9 @@ Class('Pad', {
|
|||
{
|
||||
db.getSub("pad:"+_this.id+":revs:"+keyRev, ["meta", "atext"], function(err, _atext)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
atext = Changeset.cloneAText(_atext);
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
},
|
||||
//get all needed changesets
|
||||
|
@ -175,8 +177,9 @@ Class('Pad', {
|
|||
{
|
||||
_this.getRevisionChangeset(item, function(err, changeset)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
changesets[item] = changeset;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
|
@ -199,7 +202,8 @@ Class('Pad', {
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err, atext);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, atext);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -247,8 +251,9 @@ Class('Pad', {
|
|||
{
|
||||
db.get("pad:"+_this.id+":chat:"+entryNum, function(err, _entry)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
entry = _entry;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
},
|
||||
//add the authorName
|
||||
|
@ -264,13 +269,15 @@ Class('Pad', {
|
|||
//get the authorName
|
||||
authorManager.getAuthorName(entry.userId, function(err, authorName)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
entry.userName = authorName;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err, entry);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, entry);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -311,11 +318,14 @@ Class('Pad', {
|
|||
{
|
||||
_this.getChatMessage(entryObject.entryNum, function(err, entry)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
entries[entryObject.order] = entry;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
}, function(err)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//sort out broken chat entries
|
||||
//it looks like in happend in the past that the chat head was
|
||||
//incremented, but the chat message wasn't added
|
||||
|
@ -328,7 +338,7 @@ Class('Pad', {
|
|||
console.warn("WARNING: Found broken chat entry in pad " + _this.id);
|
||||
}
|
||||
|
||||
callback(err, cleanedEntries);
|
||||
callback(null, cleanedEntries);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -345,11 +355,7 @@ Class('Pad', {
|
|||
//try to load the pad
|
||||
db.get("pad:"+this.id, function(err, value)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err, null);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//if this pad exists, load it
|
||||
if(value != null)
|
||||
|
@ -410,7 +416,7 @@ Class('Pad', {
|
|||
|
||||
db.get("group:" + groupID, function (err, group)
|
||||
{
|
||||
if(err) {callback(err); return}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//remove the pad entry
|
||||
delete group.pads[padID];
|
||||
|
@ -432,7 +438,7 @@ Class('Pad', {
|
|||
{
|
||||
readOnlyManager.getReadOnlyId(padID, function(err, readonlyID)
|
||||
{
|
||||
if(err) {callback(err); return}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
db.remove("pad2readonly:" + padID);
|
||||
db.remove("readonly2pad:" + readonlyID);
|
||||
|
@ -475,7 +481,8 @@ Class('Pad', {
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err);
|
||||
if(ERR(err, callback)) return;
|
||||
callback();
|
||||
})
|
||||
},
|
||||
//set in db
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
require("../db/Pad");
|
||||
var db = require("./DB").db;
|
||||
|
||||
|
@ -30,12 +32,20 @@ var db = require("./DB").db;
|
|||
* If this is needed in other places, it would be wise to make this a prototype
|
||||
* that's defined somewhere more sensible.
|
||||
*/
|
||||
globalPads = {
|
||||
var globalPads = {
|
||||
get: function (name) { return this[':'+name]; },
|
||||
set: function (name, value) { this[':'+name] = value; },
|
||||
remove: function (name) { delete this[':'+name]; }
|
||||
};
|
||||
|
||||
/**
|
||||
* An array of padId transformations. These represent changes in pad name policy over
|
||||
* time, and allow us to "play back" these changes so legacy padIds can be found.
|
||||
*/
|
||||
var padIdTransforms = [
|
||||
[/\s+/g, '_']
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns a Pad Object with the callback
|
||||
* @param id A String with the id of the pad
|
||||
|
@ -46,7 +56,7 @@ exports.getPad = function(id, text, callback)
|
|||
//check if this is a valid padId
|
||||
if(!exports.isValidPadId(id))
|
||||
{
|
||||
callback({stop: id + " is not a valid padId"});
|
||||
callback(new customError(id + " is not a valid padId","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -63,14 +73,14 @@ exports.getPad = function(id, text, callback)
|
|||
//check if text is a string
|
||||
if(typeof text != "string")
|
||||
{
|
||||
callback({stop: "text is not a string"});
|
||||
callback(new customError("text is not a string","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//check if text is less than 100k chars
|
||||
if(text.length > 100000)
|
||||
{
|
||||
callback({stop: "text must be less than 100k chars"});
|
||||
callback(new customError("text must be less than 100k chars","apierror"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -90,15 +100,10 @@ exports.getPad = function(id, text, callback)
|
|||
//initalize the pad
|
||||
pad.init(text, function(err)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
globalPads.set(id, pad);
|
||||
callback(null, pad);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
globalPads.set(id, pad);
|
||||
callback(null, pad);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -108,10 +113,44 @@ exports.doesPadExists = function(padId, callback)
|
|||
{
|
||||
db.get("pad:"+padId, function(err, value)
|
||||
{
|
||||
callback(err, value != null);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, value != null);
|
||||
});
|
||||
}
|
||||
|
||||
//returns a sanitized padId, respecting legacy pad id formats
|
||||
exports.sanitizePadId = function(padId, callback) {
|
||||
var transform_index = arguments[2] || 0;
|
||||
//we're out of possible transformations, so just return it
|
||||
if(transform_index >= padIdTransforms.length)
|
||||
{
|
||||
callback(padId);
|
||||
}
|
||||
//check if padId exists
|
||||
else
|
||||
{
|
||||
exports.doesPadExists(padId, function(junk, exists)
|
||||
{
|
||||
if(exists)
|
||||
{
|
||||
callback(padId);
|
||||
}
|
||||
else
|
||||
{
|
||||
//get the next transformation *that's different*
|
||||
var transformedPadId = padId;
|
||||
while(transformedPadId == padId && transform_index < padIdTransforms.length)
|
||||
{
|
||||
transformedPadId = padId.replace(padIdTransforms[transform_index][0], padIdTransforms[transform_index][1]);
|
||||
transform_index += 1;
|
||||
}
|
||||
//check the next transform
|
||||
exports.sanitizePadId(transformedPadId, callback, transform_index);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.isValidPadId = function(padId)
|
||||
{
|
||||
return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
|
||||
|
@ -55,8 +56,9 @@ exports.getReadOnlyId = function (padId, callback)
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
//return the results
|
||||
callback(err, readOnlyId);
|
||||
callback(null, readOnlyId);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
var authorManager = require("./AuthorManager");
|
||||
|
@ -56,6 +57,8 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
//get author for this token
|
||||
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
|
||||
|
@ -64,17 +67,19 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
// check if pad exists
|
||||
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
|
||||
callback(err, statusObject);
|
||||
callback(null, statusObject);
|
||||
});
|
||||
}
|
||||
// user may create new pads - no need to check anything
|
||||
else
|
||||
{
|
||||
// grant access, with author of token
|
||||
callback(err, statusObject);
|
||||
callback(null, statusObject);
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -102,8 +107,9 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
{
|
||||
padManager.doesPadExists(padID, function(err, exists)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
padExists = exists;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
},
|
||||
//get informations about this session
|
||||
|
@ -112,13 +118,13 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
sessionManager.getSessionInfo(sessionID, function(err, sessionInfo)
|
||||
{
|
||||
//skip session validation if the session doesn't exists
|
||||
if(err && err.stop == "sessionID does not exist")
|
||||
if(err && err.message == "sessionID does not exist")
|
||||
{
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
if(err) {callback(err); return}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
var now = Math.floor(new Date().getTime()/1000);
|
||||
|
||||
|
@ -139,8 +145,9 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
//get author for this token
|
||||
authorManager.getAuthor4Token(token, function(err, author)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
tokenAuthor = author;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
|
@ -157,7 +164,7 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
|
||||
padManager.getPad(padID, function(err, pad)
|
||||
{
|
||||
if(err) {callback(err); return}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//is it a public pad?
|
||||
isPublic = pad.getPublicStatus();
|
||||
|
@ -265,6 +272,7 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err, statusObject);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, statusObject);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ERR = require("async-stacktrace");
|
||||
var customError = require("../utils/customError");
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
var groupMangager = require("./GroupManager");
|
||||
|
@ -28,7 +30,8 @@ exports.doesSessionExist = function(sessionID, callback)
|
|||
//check if the database entry of this session exists
|
||||
db.get("session:" + sessionID, function (err, session)
|
||||
{
|
||||
callback(err, session != null);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, session != null);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -45,15 +48,12 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
{
|
||||
groupMangager.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//group does not exist
|
||||
else if(exists == false)
|
||||
if(exists == false)
|
||||
{
|
||||
callback({stop: "groupID does not exist"});
|
||||
callback(new customError("groupID does not exist","apierror"));
|
||||
}
|
||||
//everything is fine, continue
|
||||
else
|
||||
|
@ -67,15 +67,12 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
{
|
||||
authorMangager.doesAuthorExists(authorID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//author does not exist
|
||||
else if(exists == false)
|
||||
if(exists == false)
|
||||
{
|
||||
callback({stop: "authorID does not exist"});
|
||||
callback(new customError("authorID does not exist","apierror"));
|
||||
}
|
||||
//everything is fine, continue
|
||||
else
|
||||
|
@ -97,7 +94,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
}
|
||||
else
|
||||
{
|
||||
callback({stop: "validUntil is not a number"});
|
||||
callback(new customError("validUntil is not a number","apierror"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -105,21 +102,21 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
//ensure this is not a negativ number
|
||||
if(validUntil < 0)
|
||||
{
|
||||
callback({stop: "validUntil is a negativ number"});
|
||||
callback(new customError("validUntil is a negativ number","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//ensure this is not a float value
|
||||
if(!is_int(validUntil))
|
||||
{
|
||||
callback({stop: "validUntil is a float value"});
|
||||
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({stop: "validUntil is in the past"});
|
||||
callback(new customError("validUntil is in the past","apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -137,12 +134,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
//get the entry
|
||||
db.get("group2sessions:" + groupID, function(err, group2sessions)
|
||||
{
|
||||
//did a error happen?
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//the entry doesn't exist so far, let's create it
|
||||
if(group2sessions == null)
|
||||
|
@ -165,12 +157,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
//get the entry
|
||||
db.get("author2sessions:" + authorID, function(err, author2sessions)
|
||||
{
|
||||
//did a error happen?
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//the entry doesn't exist so far, let's create it
|
||||
if(author2sessions == null)
|
||||
|
@ -189,8 +176,10 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//return error and sessionID
|
||||
callback(err, {sessionID: sessionID});
|
||||
callback(null, {sessionID: sessionID});
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -199,15 +188,12 @@ exports.getSessionInfo = function(sessionID, callback)
|
|||
//check if the database entry of this session exists
|
||||
db.get("session:" + sessionID, function (err, session)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//session does not exists
|
||||
else if(session == null)
|
||||
if(session == null)
|
||||
{
|
||||
callback({stop: "sessionID does not exist"})
|
||||
callback(new customError("sessionID does not exist","apierror"))
|
||||
}
|
||||
//everything is fine, return the sessioninfos
|
||||
else
|
||||
|
@ -231,15 +217,12 @@ exports.deleteSession = function(sessionID, callback)
|
|||
//get the session entry
|
||||
db.get("session:" + sessionID, function (err, session)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//session does not exists
|
||||
else if(session == null)
|
||||
if(session == null)
|
||||
{
|
||||
callback({stop: "sessionID does not exist"})
|
||||
callback(new customError("sessionID does not exist","apierror"))
|
||||
}
|
||||
//everything is fine, return the sessioninfos
|
||||
else
|
||||
|
@ -256,8 +239,9 @@ exports.deleteSession = function(sessionID, callback)
|
|||
{
|
||||
db.get("group2sessions:" + groupID, function (err, _group2sessions)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
group2sessions = _group2sessions;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
},
|
||||
//get the author2sessions entry
|
||||
|
@ -265,8 +249,9 @@ exports.deleteSession = function(sessionID, callback)
|
|||
{
|
||||
db.get("author2sessions:" + authorID, function (err, _author2sessions)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
author2sessions = _author2sessions;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
},
|
||||
//remove the values from the database
|
||||
|
@ -287,7 +272,8 @@ exports.deleteSession = function(sessionID, callback)
|
|||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err);
|
||||
if(ERR(err, callback)) return;
|
||||
callback();
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -295,15 +281,12 @@ exports.listSessionsOfGroup = function(groupID, callback)
|
|||
{
|
||||
groupMangager.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//group does not exist
|
||||
else if(exists == false)
|
||||
if(exists == false)
|
||||
{
|
||||
callback({stop: "groupID does not exist"});
|
||||
callback(new customError("groupID does not exist","apierror"));
|
||||
}
|
||||
//everything is fine, continue
|
||||
else
|
||||
|
@ -317,15 +300,12 @@ exports.listSessionsOfAuthor = function(authorID, callback)
|
|||
{
|
||||
authorMangager.doesAuthorExists(authorID, function(err, exists)
|
||||
{
|
||||
//error
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
}
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//group does not exist
|
||||
else if(exists == false)
|
||||
if(exists == false)
|
||||
{
|
||||
callback({stop: "authorID does not exist"});
|
||||
callback(new customError("authorID does not exist","apierror"));
|
||||
}
|
||||
//everything is fine, continue
|
||||
else
|
||||
|
@ -346,8 +326,9 @@ function listSessionsWithDBKey (dbkey, callback)
|
|||
//get the group2sessions entry
|
||||
db.get(dbkey, function(err, sessionObject)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
sessions = sessionObject ? sessionObject.sessionIDs : null;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
},
|
||||
function(callback)
|
||||
|
@ -364,14 +345,16 @@ function listSessionsWithDBKey (dbkey, callback)
|
|||
{
|
||||
exports.getSessionInfo(sessionID, function(err, sessionInfo)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
sessions[sessionID] = sessionInfo;
|
||||
callback(err);
|
||||
callback();
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
], function(err)
|
||||
{
|
||||
callback(err, sessions);
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, sessions);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue