mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 00:16:15 -04:00
lint: Put opening brace on same line as function
Normally I would let `eslint --fix` do this for me, but there's a bug that causes: const x = function () { // ... }; to become: const x = () => { // ... }; which ESLint thinks is a syntax error. (It probably is; I don't know enough about the automatic semicolon insertion rules to be confident.)
This commit is contained in:
parent
cc988bd67b
commit
7df3ded66f
66 changed files with 1036 additions and 2072 deletions
|
@ -101,8 +101,7 @@ Example returns:
|
|||
}
|
||||
|
||||
*/
|
||||
exports.getAttributePool = async function(padID)
|
||||
{
|
||||
exports.getAttributePool = async function(padID) {
|
||||
let pad = await getPadSafe(padID, true);
|
||||
return { pool: pad.pool };
|
||||
}
|
||||
|
@ -120,8 +119,7 @@ Example returns:
|
|||
}
|
||||
|
||||
*/
|
||||
exports.getRevisionChangeset = async function(padID, rev)
|
||||
{
|
||||
exports.getRevisionChangeset = async function(padID, rev) {
|
||||
// try to parse the revision number
|
||||
if (rev !== undefined) {
|
||||
rev = checkValidRev(rev);
|
||||
|
@ -155,8 +153,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {text:"Welcome Text"}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getText = async function(padID, rev)
|
||||
{
|
||||
exports.getText = async function(padID, rev) {
|
||||
// try to parse the revision number
|
||||
if (rev !== undefined) {
|
||||
rev = checkValidRev(rev);
|
||||
|
@ -193,8 +190,7 @@ Example returns:
|
|||
{code: 1, message:"padID does not exist", data: null}
|
||||
{code: 1, message:"text too long", data: null}
|
||||
*/
|
||||
exports.setText = async function(padID, text)
|
||||
{
|
||||
exports.setText = async function(padID, text) {
|
||||
// text is required
|
||||
if (typeof text !== "string") {
|
||||
throw new customError("text is not a string", "apierror");
|
||||
|
@ -218,8 +214,7 @@ Example returns:
|
|||
{code: 1, message:"padID does not exist", data: null}
|
||||
{code: 1, message:"text too long", data: null}
|
||||
*/
|
||||
exports.appendText = async function(padID, text)
|
||||
{
|
||||
exports.appendText = async function(padID, text) {
|
||||
// text is required
|
||||
if (typeof text !== "string") {
|
||||
throw new customError("text is not a string", "apierror");
|
||||
|
@ -240,8 +235,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {text:"Welcome <strong>Text</strong>"}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getHTML = async function(padID, rev)
|
||||
{
|
||||
exports.getHTML = async function(padID, rev) {
|
||||
if (rev !== undefined) {
|
||||
rev = checkValidRev(rev);
|
||||
}
|
||||
|
@ -273,8 +267,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.setHTML = async function(padID, html)
|
||||
{
|
||||
exports.setHTML = async function(padID, html) {
|
||||
// html string is required
|
||||
if (typeof html !== "string") {
|
||||
throw new customError("html is not a string", "apierror");
|
||||
|
@ -310,8 +303,7 @@ Example returns:
|
|||
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getChatHistory = async function(padID, start, end)
|
||||
{
|
||||
exports.getChatHistory = async function(padID, start, end) {
|
||||
if (start && end) {
|
||||
if (start < 0) {
|
||||
throw new customError("start is below zero", "apierror");
|
||||
|
@ -356,8 +348,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.appendChatMessage = async function(padID, text, authorID, time)
|
||||
{
|
||||
exports.appendChatMessage = async function(padID, text, authorID, time) {
|
||||
// text is required
|
||||
if (typeof text !== "string") {
|
||||
throw new customError("text is not a string", "apierror");
|
||||
|
@ -386,8 +377,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {revisions: 56}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getRevisionsCount = async function(padID)
|
||||
{
|
||||
exports.getRevisionsCount = async function(padID) {
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
return { revisions: pad.getHeadRevisionNumber() };
|
||||
|
@ -401,8 +391,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {savedRevisions: 42}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getSavedRevisionsCount = async function(padID)
|
||||
{
|
||||
exports.getSavedRevisionsCount = async function(padID) {
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
return { savedRevisions: pad.getSavedRevisionsNumber() };
|
||||
|
@ -416,8 +405,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {savedRevisions: [2, 42, 1337]}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.listSavedRevisions = async function(padID)
|
||||
{
|
||||
exports.listSavedRevisions = async function(padID) {
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
return { savedRevisions: pad.getSavedRevisionsList() };
|
||||
|
@ -431,8 +419,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.saveRevision = async function(padID, rev)
|
||||
{
|
||||
exports.saveRevision = async function(padID, rev) {
|
||||
// check if rev is a number
|
||||
if (rev !== undefined) {
|
||||
rev = checkValidRev(rev);
|
||||
|
@ -463,8 +450,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {lastEdited: 1340815946602}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getLastEdited = async function(padID)
|
||||
{
|
||||
exports.getLastEdited = async function(padID) {
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
let lastEdited = await pad.getLastEdit();
|
||||
|
@ -479,8 +465,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"pad does already exist", data: null}
|
||||
*/
|
||||
exports.createPad = async function(padID, text)
|
||||
{
|
||||
exports.createPad = async function(padID, text) {
|
||||
if (padID) {
|
||||
// ensure there is no $ in the padID
|
||||
if (padID.indexOf("$") !== -1) {
|
||||
|
@ -505,8 +490,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.deletePad = async function(padID)
|
||||
{
|
||||
exports.deletePad = async function(padID) {
|
||||
let pad = await getPadSafe(padID, true);
|
||||
await pad.remove();
|
||||
}
|
||||
|
@ -519,8 +503,7 @@ exports.deletePad = async function(padID)
|
|||
{code:0, message:"ok", data:null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.restoreRevision = async function(padID, rev)
|
||||
{
|
||||
exports.restoreRevision = async function(padID, rev) {
|
||||
// check if rev is a number
|
||||
if (rev === undefined) {
|
||||
throw new customError("rev is not defined", "apierror");
|
||||
|
@ -588,8 +571,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {padID: destinationID}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.copyPad = async function(sourceID, destinationID, force)
|
||||
{
|
||||
exports.copyPad = async function(sourceID, destinationID, force) {
|
||||
let pad = await getPadSafe(sourceID, true);
|
||||
await pad.copy(destinationID, force);
|
||||
}
|
||||
|
@ -603,8 +585,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {padID: destinationID}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.copyPadWithoutHistory = async function(sourceID, destinationID, force)
|
||||
{
|
||||
exports.copyPadWithoutHistory = async function(sourceID, destinationID, force) {
|
||||
let pad = await getPadSafe(sourceID, true);
|
||||
await pad.copyPadWithoutHistory(destinationID, force);
|
||||
}
|
||||
|
@ -618,8 +599,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {padID: destinationID}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.movePad = async function(sourceID, destinationID, force)
|
||||
{
|
||||
exports.movePad = async function(sourceID, destinationID, force) {
|
||||
let pad = await getPadSafe(sourceID, true);
|
||||
await pad.copy(destinationID, force);
|
||||
await pad.remove();
|
||||
|
@ -633,8 +613,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getReadOnlyID = async function(padID)
|
||||
{
|
||||
exports.getReadOnlyID = async function(padID) {
|
||||
// we don't need the pad object, but this function does all the security stuff for us
|
||||
await getPadSafe(padID, true);
|
||||
|
||||
|
@ -652,8 +631,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {padID: padID}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getPadID = async function(roID)
|
||||
{
|
||||
exports.getPadID = async function(roID) {
|
||||
// get the PadId
|
||||
let padID = await readOnlyManager.getPadId(roID);
|
||||
if (padID === null) {
|
||||
|
@ -671,8 +649,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.setPublicStatus = async function(padID, publicStatus)
|
||||
{
|
||||
exports.setPublicStatus = async function(padID, publicStatus) {
|
||||
// ensure this is a group pad
|
||||
checkGroupPad(padID, "publicStatus");
|
||||
|
||||
|
@ -695,8 +672,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {publicStatus: true}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getPublicStatus = async function(padID)
|
||||
{
|
||||
exports.getPublicStatus = async function(padID) {
|
||||
// ensure this is a group pad
|
||||
checkGroupPad(padID, "publicStatus");
|
||||
|
||||
|
@ -713,8 +689,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {authorIDs : ["a.s8oes9dhwrvt0zif", "a.akf8finncvomlqva"]}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.listAuthorsOfPad = async function(padID)
|
||||
{
|
||||
exports.listAuthorsOfPad = async function(padID) {
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
let authorIDs = pad.getAllAuthors();
|
||||
|
@ -757,8 +732,7 @@ Example returns:
|
|||
{"code":0,"message":"ok","data":null}
|
||||
{"code":4,"message":"no or wrong API Key","data":null}
|
||||
*/
|
||||
exports.checkToken = async function()
|
||||
{
|
||||
exports.checkToken = async function() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -769,8 +743,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {chatHead: 42}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getChatHead = async function(padID)
|
||||
{
|
||||
exports.getChatHead = async function(padID) {
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
return { chatHead: pad.chatHead };
|
||||
|
@ -843,14 +816,12 @@ exports.getStats = async function() {
|
|||
/******************************/
|
||||
|
||||
// checks if a number is an int
|
||||
function is_int(value)
|
||||
{
|
||||
function is_int(value) {
|
||||
return (parseFloat(value) == parseInt(value, 10)) && !isNaN(value)
|
||||
}
|
||||
|
||||
// gets a pad safe
|
||||
async function getPadSafe(padID, shouldExist, text)
|
||||
{
|
||||
async function getPadSafe(padID, shouldExist, text) {
|
||||
// check if padID is a string
|
||||
if (typeof padID !== "string") {
|
||||
throw new customError("padID is not a string", "apierror");
|
||||
|
@ -880,8 +851,7 @@ async function getPadSafe(padID, shouldExist, text)
|
|||
|
||||
// checks if a rev is a legal number
|
||||
// pre-condition is that `rev` is not undefined
|
||||
function checkValidRev(rev)
|
||||
{
|
||||
function checkValidRev(rev) {
|
||||
if (typeof rev !== "number") {
|
||||
rev = parseInt(rev, 10);
|
||||
}
|
||||
|
@ -905,8 +875,7 @@ function checkValidRev(rev)
|
|||
}
|
||||
|
||||
// checks if a padID is part of a group
|
||||
function checkGroupPad(padID, field)
|
||||
{
|
||||
function checkGroupPad(padID, field) {
|
||||
// ensure this is a group pad
|
||||
if (padID && padID.indexOf("$") === -1) {
|
||||
throw new customError(`You can only get/set the ${field} of pads that belong to a group`, "apierror");
|
||||
|
|
|
@ -38,8 +38,7 @@ exports.getColorPalette = function() {
|
|||
/**
|
||||
* Checks if the author exists
|
||||
*/
|
||||
exports.doesAuthorExist = async function(authorID)
|
||||
{
|
||||
exports.doesAuthorExist = async function(authorID) {
|
||||
let author = await db.get("globalAuthor:" + authorID);
|
||||
|
||||
return author !== null;
|
||||
|
@ -52,8 +51,7 @@ exports.doesAuthorExists = exports.doesAuthorExist;
|
|||
* Returns the AuthorID for a token.
|
||||
* @param {String} token The token
|
||||
*/
|
||||
exports.getAuthor4Token = async function(token)
|
||||
{
|
||||
exports.getAuthor4Token = async function(token) {
|
||||
let author = await mapAuthorWithDBKey("token2author", token);
|
||||
|
||||
// return only the sub value authorID
|
||||
|
@ -65,8 +63,7 @@ exports.getAuthor4Token = async function(token)
|
|||
* @param {String} token The mapper
|
||||
* @param {String} name The name of the author (optional)
|
||||
*/
|
||||
exports.createAuthorIfNotExistsFor = async function(authorMapper, name)
|
||||
{
|
||||
exports.createAuthorIfNotExistsFor = async function(authorMapper, name) {
|
||||
let author = await mapAuthorWithDBKey("mapper2author", authorMapper);
|
||||
|
||||
if (name) {
|
||||
|
@ -83,8 +80,7 @@ exports.createAuthorIfNotExistsFor = async function(authorMapper, name)
|
|||
* @param {String} mapperkey The database key name for this mapper
|
||||
* @param {String} mapper The mapper
|
||||
*/
|
||||
async function mapAuthorWithDBKey (mapperkey, mapper)
|
||||
{
|
||||
async function mapAuthorWithDBKey (mapperkey, mapper) {
|
||||
// try to map to an author
|
||||
let author = await db.get(mapperkey + ":" + mapper);
|
||||
|
||||
|
@ -111,8 +107,7 @@ async function mapAuthorWithDBKey (mapperkey, mapper)
|
|||
* Internal function that creates the database entry for an author
|
||||
* @param {String} name The name of the author
|
||||
*/
|
||||
exports.createAuthor = function(name)
|
||||
{
|
||||
exports.createAuthor = function(name) {
|
||||
// create the new author name
|
||||
let author = "a." + randomString(16);
|
||||
|
||||
|
@ -134,8 +129,7 @@ exports.createAuthor = function(name)
|
|||
* Returns the Author Obj of the author
|
||||
* @param {String} author The id of the author
|
||||
*/
|
||||
exports.getAuthor = function(author)
|
||||
{
|
||||
exports.getAuthor = function(author) {
|
||||
// NB: result is already a Promise
|
||||
return db.get("globalAuthor:" + author);
|
||||
}
|
||||
|
@ -144,8 +138,7 @@ exports.getAuthor = function(author)
|
|||
* Returns the color Id of the author
|
||||
* @param {String} author The id of the author
|
||||
*/
|
||||
exports.getAuthorColorId = function(author)
|
||||
{
|
||||
exports.getAuthorColorId = function(author) {
|
||||
return db.getSub("globalAuthor:" + author, ["colorId"]);
|
||||
}
|
||||
|
||||
|
@ -154,8 +147,7 @@ exports.getAuthorColorId = function(author)
|
|||
* @param {String} author The id of the author
|
||||
* @param {String} colorId The color id of the author
|
||||
*/
|
||||
exports.setAuthorColorId = function(author, colorId)
|
||||
{
|
||||
exports.setAuthorColorId = function(author, colorId) {
|
||||
return db.setSub("globalAuthor:" + author, ["colorId"], colorId);
|
||||
}
|
||||
|
||||
|
@ -163,8 +155,7 @@ exports.setAuthorColorId = function(author, colorId)
|
|||
* Returns the name of the author
|
||||
* @param {String} author The id of the author
|
||||
*/
|
||||
exports.getAuthorName = function(author)
|
||||
{
|
||||
exports.getAuthorName = function(author) {
|
||||
return db.getSub("globalAuthor:" + author, ["name"]);
|
||||
}
|
||||
|
||||
|
@ -173,8 +164,7 @@ exports.getAuthorName = function(author)
|
|||
* @param {String} author The id of the author
|
||||
* @param {String} name The name of the author
|
||||
*/
|
||||
exports.setAuthorName = function(author, name)
|
||||
{
|
||||
exports.setAuthorName = function(author, name) {
|
||||
return db.setSub("globalAuthor:" + author, ["name"], name);
|
||||
}
|
||||
|
||||
|
@ -182,8 +172,7 @@ exports.setAuthorName = function(author, name)
|
|||
* Returns an array of all pads this author contributed to
|
||||
* @param {String} author The id of the author
|
||||
*/
|
||||
exports.listPadsOfAuthor = async function(authorID)
|
||||
{
|
||||
exports.listPadsOfAuthor = async function(authorID) {
|
||||
/* There are two other places where this array is manipulated:
|
||||
* (1) When the author is added to a pad, the author object is also updated
|
||||
* (2) When a pad is deleted, each author of that pad is also updated
|
||||
|
@ -208,8 +197,7 @@ exports.listPadsOfAuthor = async function(authorID)
|
|||
* @param {String} author The id of the author
|
||||
* @param {String} padID The id of the pad the author contributes to
|
||||
*/
|
||||
exports.addPad = async function(authorID, padID)
|
||||
{
|
||||
exports.addPad = async function(authorID, padID) {
|
||||
// get the entry
|
||||
let author = await db.get("globalAuthor:" + authorID);
|
||||
|
||||
|
@ -236,8 +224,7 @@ exports.addPad = async function(authorID, padID)
|
|||
* @param {String} author The id of the author
|
||||
* @param {String} padID The id of the pad the author contributes to
|
||||
*/
|
||||
exports.removePad = async function(authorID, padID)
|
||||
{
|
||||
exports.removePad = async function(authorID, padID) {
|
||||
let author = await db.get("globalAuthor:" + authorID);
|
||||
|
||||
if (author === null) return;
|
||||
|
|
|
@ -24,8 +24,7 @@ var db = require("./DB");
|
|||
var padManager = require("./PadManager");
|
||||
var sessionManager = require("./SessionManager");
|
||||
|
||||
exports.listAllGroups = async function()
|
||||
{
|
||||
exports.listAllGroups = async function() {
|
||||
let groups = await db.get("groups");
|
||||
groups = groups || {};
|
||||
|
||||
|
@ -33,8 +32,7 @@ exports.listAllGroups = async function()
|
|||
return { groupIDs };
|
||||
}
|
||||
|
||||
exports.deleteGroup = async function(groupID)
|
||||
{
|
||||
exports.deleteGroup = async function(groupID) {
|
||||
let group = await db.get("group:" + groupID);
|
||||
|
||||
// ensure group exists
|
||||
|
@ -82,16 +80,14 @@ exports.deleteGroup = async function(groupID)
|
|||
await db.set("groups", newGroups);
|
||||
}
|
||||
|
||||
exports.doesGroupExist = async function(groupID)
|
||||
{
|
||||
exports.doesGroupExist = async function(groupID) {
|
||||
// try to get the group entry
|
||||
let group = await db.get("group:" + groupID);
|
||||
|
||||
return (group != null);
|
||||
}
|
||||
|
||||
exports.createGroup = async function()
|
||||
{
|
||||
exports.createGroup = async function() {
|
||||
// search for non existing groupID
|
||||
var groupID = "g." + randomString(16);
|
||||
|
||||
|
@ -111,8 +107,7 @@ exports.createGroup = async function()
|
|||
return { groupID };
|
||||
}
|
||||
|
||||
exports.createGroupIfNotExistsFor = async function(groupMapper)
|
||||
{
|
||||
exports.createGroupIfNotExistsFor = async function(groupMapper) {
|
||||
// ensure mapper is optional
|
||||
if (typeof groupMapper !== "string") {
|
||||
throw new customError("groupMapper is not a string", "apierror");
|
||||
|
@ -137,8 +132,7 @@ exports.createGroupIfNotExistsFor = async function(groupMapper)
|
|||
return result;
|
||||
}
|
||||
|
||||
exports.createGroupPad = async function(groupID, padName, text)
|
||||
{
|
||||
exports.createGroupPad = async function(groupID, padName, text) {
|
||||
// create the padID
|
||||
let padID = groupID + "$" + padName;
|
||||
|
||||
|
@ -166,8 +160,7 @@ exports.createGroupPad = async function(groupID, padName, text)
|
|||
return { padID };
|
||||
}
|
||||
|
||||
exports.listPads = async function(groupID)
|
||||
{
|
||||
exports.listPads = async function(groupID) {
|
||||
let exists = await exports.doesGroupExist(groupID);
|
||||
|
||||
// ensure the group exists
|
||||
|
|
|
@ -109,8 +109,7 @@ let padList = {
|
|||
* @param id A String with the id of the pad
|
||||
* @param {Function} callback
|
||||
*/
|
||||
exports.getPad = async function(id, text)
|
||||
{
|
||||
exports.getPad = async function(id, text) {
|
||||
// check if this is a valid padId
|
||||
if (!exports.isValidPadId(id)) {
|
||||
throw new customError(id + " is not a valid padId", "apierror");
|
||||
|
@ -147,16 +146,14 @@ exports.getPad = async function(id, text)
|
|||
return pad;
|
||||
}
|
||||
|
||||
exports.listAllPads = async function()
|
||||
{
|
||||
exports.listAllPads = async function() {
|
||||
let padIDs = await padList.getPads();
|
||||
|
||||
return { padIDs };
|
||||
}
|
||||
|
||||
// checks if a pad exists
|
||||
exports.doesPadExist = async function(padId)
|
||||
{
|
||||
exports.doesPadExist = async function(padId) {
|
||||
let value = await db.get("pad:" + padId);
|
||||
|
||||
return (value != null && value.atext);
|
||||
|
@ -192,8 +189,7 @@ exports.sanitizePadId = async function sanitizePadId(padId) {
|
|||
return padId;
|
||||
}
|
||||
|
||||
exports.isValidPadId = function(padId)
|
||||
{
|
||||
exports.isValidPadId = function(padId) {
|
||||
return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId);
|
||||
}
|
||||
|
||||
|
@ -208,7 +204,6 @@ exports.removePad = async (padId) => {
|
|||
}
|
||||
|
||||
// removes a pad from the cache
|
||||
exports.unloadPad = function(padId)
|
||||
{
|
||||
exports.unloadPad = function(padId) {
|
||||
globalPads.remove(padId);
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@ var randomString = require("../utils/randomstring");
|
|||
* checks if the id pattern matches a read-only pad id
|
||||
* @param {String} the pad's id
|
||||
*/
|
||||
exports.isReadOnlyId = function(id)
|
||||
{
|
||||
exports.isReadOnlyId = function(id) {
|
||||
return id.indexOf("r.") === 0;
|
||||
}
|
||||
|
||||
|
@ -36,8 +35,7 @@ exports.isReadOnlyId = function(id)
|
|||
* returns a read only id for a pad
|
||||
* @param {String} padId the id of the pad
|
||||
*/
|
||||
exports.getReadOnlyId = async function (padId)
|
||||
{
|
||||
exports.getReadOnlyId = async function (padId) {
|
||||
// check if there is a pad2readonly entry
|
||||
let readOnlyId = await db.get("pad2readonly:" + padId);
|
||||
|
||||
|
@ -55,8 +53,7 @@ exports.getReadOnlyId = async function (padId)
|
|||
* returns the padId for a read only id
|
||||
* @param {String} readOnlyId read only id
|
||||
*/
|
||||
exports.getPadId = function(readOnlyId)
|
||||
{
|
||||
exports.getPadId = function(readOnlyId) {
|
||||
return db.get("readonly2pad:" + readOnlyId);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,7 @@ const DENY = Object.freeze({accessStatus: 'deny'});
|
|||
* WARNING: Tokens and session IDs MUST be kept secret, otherwise users will be able to impersonate
|
||||
* each other (which might allow them to gain privileges).
|
||||
*/
|
||||
exports.checkAccess = async function(padID, sessionCookie, token, userSettings)
|
||||
{
|
||||
exports.checkAccess = async function(padID, sessionCookie, token, userSettings) {
|
||||
if (!padID) {
|
||||
authLogger.debug('access denied: missing padID');
|
||||
return DENY;
|
||||
|
|
|
@ -78,8 +78,7 @@ exports.findAuthorID = async (groupID, sessionCookie) => {
|
|||
return sessionInfo.authorID;
|
||||
};
|
||||
|
||||
exports.doesSessionExist = async function(sessionID)
|
||||
{
|
||||
exports.doesSessionExist = async function(sessionID) {
|
||||
//check if the database entry of this session exists
|
||||
let session = await db.get("session:" + sessionID);
|
||||
return (session !== null);
|
||||
|
@ -88,8 +87,7 @@ exports.doesSessionExist = async function(sessionID)
|
|||
/**
|
||||
* Creates a new session between an author and a group
|
||||
*/
|
||||
exports.createSession = async function(groupID, authorID, validUntil)
|
||||
{
|
||||
exports.createSession = async function(groupID, authorID, validUntil) {
|
||||
// check if the group exists
|
||||
let groupExists = await groupManager.doesGroupExist(groupID);
|
||||
if (!groupExists) {
|
||||
|
@ -172,8 +170,7 @@ exports.createSession = async function(groupID, authorID, validUntil)
|
|||
return { sessionID };
|
||||
}
|
||||
|
||||
exports.getSessionInfo = async function(sessionID)
|
||||
{
|
||||
exports.getSessionInfo = async function(sessionID) {
|
||||
// check if the database entry of this session exists
|
||||
let session = await db.get("session:" + sessionID);
|
||||
|
||||
|
@ -189,8 +186,7 @@ exports.getSessionInfo = async function(sessionID)
|
|||
/**
|
||||
* Deletes a session
|
||||
*/
|
||||
exports.deleteSession = async function(sessionID)
|
||||
{
|
||||
exports.deleteSession = async function(sessionID) {
|
||||
// ensure that the session exists
|
||||
let session = await db.get("session:" + sessionID);
|
||||
if (session == null) {
|
||||
|
@ -221,8 +217,7 @@ exports.deleteSession = async function(sessionID)
|
|||
}
|
||||
}
|
||||
|
||||
exports.listSessionsOfGroup = async function(groupID)
|
||||
{
|
||||
exports.listSessionsOfGroup = async function(groupID) {
|
||||
// check that the group exists
|
||||
let exists = await groupManager.doesGroupExist(groupID);
|
||||
if (!exists) {
|
||||
|
@ -233,8 +228,7 @@ exports.listSessionsOfGroup = async function(groupID)
|
|||
return sessions;
|
||||
}
|
||||
|
||||
exports.listSessionsOfAuthor = async function(authorID)
|
||||
{
|
||||
exports.listSessionsOfAuthor = async function(authorID) {
|
||||
// check that the author exists
|
||||
let exists = await authorManager.doesAuthorExist(authorID)
|
||||
if (!exists) {
|
||||
|
@ -247,8 +241,7 @@ exports.listSessionsOfAuthor = async function(authorID)
|
|||
|
||||
// this function is basically the code listSessionsOfAuthor and listSessionsOfGroup has in common
|
||||
// required to return null rather than an empty object if there are none
|
||||
async function listSessionsWithDBKey(dbkey)
|
||||
{
|
||||
async function listSessionsWithDBKey(dbkey) {
|
||||
// get the group2sessions entry
|
||||
let sessionObject = await db.get(dbkey);
|
||||
let sessions = sessionObject ? sessionObject.sessionIDs : null;
|
||||
|
@ -272,7 +265,6 @@ async function listSessionsWithDBKey(dbkey)
|
|||
}
|
||||
|
||||
// checks if a number is an int
|
||||
function is_int(value)
|
||||
{
|
||||
function is_int(value) {
|
||||
return (parseFloat(value) == parseInt(value)) && !isNaN(value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue