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:
Richard Hansen 2020-11-21 13:37:57 -05:00 committed by John McLear
parent cc988bd67b
commit 7df3ded66f
66 changed files with 1036 additions and 2072 deletions

View file

@ -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");

View file

@ -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;

View file

@ -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

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;

View file

@ -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);
}

View file

@ -158,8 +158,7 @@ exports.version = version;
* @req express request object
* @res express response object
*/
exports.handle = async function(apiVersion, functionName, fields, req, res)
{
exports.handle = async function(apiVersion, functionName, fields, req, res) {
// say goodbye if this is an unknown API version
if (!(apiVersion in version)) {
throw new createHTTPError.NotFound('no such api version');

View file

@ -49,8 +49,7 @@ const tempDirectory = os.tmpdir();
/**
* do a requested export
*/
async function doExport(req, res, padId, readOnlyId, type)
{
async function doExport(req, res, padId, readOnlyId, type) {
// avoid naming the read-only file as the original pad's id
var fileName = readOnlyId ? readOnlyId : padId;
@ -131,8 +130,7 @@ async function doExport(req, res, padId, readOnlyId, type)
}
}
exports.doExport = function(req, res, padId, readOnlyId, type)
{
exports.doExport = function(req, res, padId, readOnlyId, type) {
doExport(req, res, padId, readOnlyId, type).catch(err => {
if (err !== "stop") {
throw err;

View file

@ -57,8 +57,7 @@ const tmpDirectory = os.tmpdir();
/**
* do a requested import
*/
async function doImport(req, res, padId)
{
async function doImport(req, res, padId) {
var apiLogger = log4js.getLogger("ImportHandler");
// pipe to a file
@ -265,8 +264,7 @@ async function doImport(req, res, padId)
}
}
exports.doImport = function (req, res, padId)
{
exports.doImport = function (req, res, padId) {
/**
* NB: abuse the 'req' object by storing an additional
* 'directDatabaseAccess' property on it so that it can

View file

@ -80,8 +80,7 @@ let socketio;
* This Method is called by server.js to tell the message handler on which socket it should send
* @param socket_io The Socket
*/
exports.setSocketIO = function(socket_io)
{
exports.setSocketIO = function(socket_io) {
socketio=socket_io;
}
@ -99,8 +98,7 @@ exports.handleConnect = (socket) => {
/**
* Kicks all sessions from a pad
*/
exports.kickSessionsFromPad = function(padID)
{
exports.kickSessionsFromPad = function(padID) {
if(typeof socketio.sockets['clients'] !== 'function')
return;
@ -355,8 +353,7 @@ async function handleChatMessage(socket, message) {
* @param text the text of the chat message
* @param padId the padId to send the chat message to
*/
exports.sendChatMessageToPadClients = async function(time, userId, text, padId)
{
exports.sendChatMessageToPadClients = async function(time, userId, text, padId) {
// get the pad
let pad = await padManager.getPad(padId);
@ -688,8 +685,7 @@ async function handleUserChanges(socket, message) {
stopWatch.end();
}
exports.updatePadClients = async function(pad)
{
exports.updatePadClients = async function(pad) {
// skip this if no-one is on this pad
const roomSockets = _getRoomSockets(pad.id);
if (roomSockets.length === 0) return;
@ -837,8 +833,7 @@ async function handleSwitchToPad(socket, message, _authorID) {
}
// Creates/replaces the auth object in the given session info.
function createSessionInfoAuth(sessionInfo, message)
{
function createSessionInfoAuth(sessionInfo, message) {
// Remember this information since we won't
// have the cookie in further socket.io messages.
// This information will be used to check if
@ -1250,8 +1245,7 @@ async function handleChangesetRequest(socket, message) {
* Tries to rebuild the getChangestInfo function of the original Etherpad
* https://github.com/ether/pad/blob/master/etherpad/src/etherpad/control/pad/pad_changeset_control.js#L144
*/
async function getChangesetInfo(padId, startNum, endNum, granularity)
{
async function getChangesetInfo(padId, startNum, endNum, granularity) {
let pad = await padManager.getPad(padId);
let head_revision = pad.getHeadRevisionNumber();
@ -1344,8 +1338,7 @@ async function getChangesetInfo(padId, startNum, endNum, granularity)
* Tries to rebuild the getPadLines function of the original Etherpad
* https://github.com/ether/pad/blob/master/etherpad/src/etherpad/control/pad/pad_changeset_control.js#L263
*/
async function getPadLines(padId, revNum)
{
async function getPadLines(padId, revNum) {
let pad = await padManager.getPad(padId);
// get the atext
@ -1367,8 +1360,7 @@ async function getPadLines(padId, revNum)
* Tries to rebuild the composePadChangeset function of the original Etherpad
* https://github.com/ether/pad/blob/master/etherpad/src/etherpad/control/pad/pad_changeset_control.js#L241
*/
async function composePadChangesets (padId, startNum, endNum)
{
async function composePadChangesets (padId, startNum, endNum) {
let pad = await padManager.getPad(padId);
// fetch all changesets we need

View file

@ -37,8 +37,7 @@ var socket;
/**
* adds a component
*/
exports.addComponent = function(moduleName, module)
{
exports.addComponent = function(moduleName, module) {
// save the component
components[moduleName] = module;
@ -53,8 +52,7 @@ exports.setSocketIO = function(_socket) {
// save this socket internaly
socket = _socket;
socket.sockets.on('connection', function(client)
{
socket.sockets.on('connection', function(client) {
// wrap the original send function to log the messages
client._send = client.send;
client.send = function(message) {

View file

@ -12,24 +12,20 @@ exports.expressCreateServer = function (hook_name, args, cb) {
})
//serve index.html under /
args.app.get('/', function(req, res)
{
args.app.get('/', function(req, res) {
res.send(eejs.require('ep_etherpad-lite/templates/index.html', {req}));
});
//serve javascript.html
args.app.get('/javascript', function(req, res)
{
args.app.get('/javascript', function(req, res) {
res.send(eejs.require('ep_etherpad-lite/templates/javascript.html', {req}));
});
//serve robots.txt
args.app.get('/robots.txt', function(req, res)
{
args.app.get('/robots.txt', function(req, res) {
var filePath = path.join(settings.root, "src", "static", "skins", settings.skinName, "robots.txt");
res.sendFile(filePath, function(err)
{
res.sendFile(filePath, function(err) {
//there is no custom robots.txt, send the default robots.txt which dissallows all
if(err)
{
@ -40,8 +36,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
});
//serve pad.html under /p
args.app.get('/p/:pad', function(req, res, next)
{
args.app.get('/p/:pad', function(req, res, next) {
// The below might break for pads being rewritten
const isReadOnly =
req.url.indexOf("/p/r.") === 0 || !webaccess.userCanModify(req.params.pad, req);
@ -59,8 +54,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
});
//serve timeslider.html under /p/$padname/timeslider
args.app.get('/p/:pad/timeslider', function(req, res, next)
{
args.app.get('/p/:pad/timeslider', function(req, res, next) {
hooks.callAll("padInitToolbar", {
toolbar: toolbar
});
@ -72,12 +66,10 @@ exports.expressCreateServer = function (hook_name, args, cb) {
});
//serve favicon.ico from all path levels except as a pad name
args.app.get( /\/favicon.ico$/, function(req, res)
{
args.app.get( /\/favicon.ico$/, function(req, res) {
var filePath = path.join(settings.root, "src", "static", "skins", settings.skinName, "favicon.ico");
res.sendFile(filePath, function(err)
{
res.sendFile(filePath, function(err) {
//there is no custom favicon, send the default favicon
if(err)
{

View file

@ -30,27 +30,23 @@ if(os.type().indexOf("Windows") > -1)
{
var stdoutBuffer = "";
doConvertTask = function(task, callback)
{
doConvertTask = function(task, callback) {
//span an abiword process to perform the conversion
var abiword = spawn(settings.abiword, ["--to=" + task.destFile, task.srcFile]);
//delegate the processing of stdout to another function
abiword.stdout.on('data', function (data)
{
abiword.stdout.on('data', function (data) {
//add data to buffer
stdoutBuffer+=data.toString();
});
//append error messages to the buffer
abiword.stderr.on('data', function (data)
{
abiword.stderr.on('data', function (data) {
stdoutBuffer += data.toString();
});
//throw exceptions if abiword is dieing
abiword.on('exit', function (code)
{
abiword.on('exit', function (code) {
if(code != 0) {
return callback(`Abiword died with exit code ${code}`);
}
@ -64,8 +60,7 @@ if(os.type().indexOf("Windows") > -1)
});
};
exports.convertFile = function(srcFile, destFile, type, callback)
{
exports.convertFile = function(srcFile, destFile, type, callback) {
doConvertTask({"srcFile": srcFile, "destFile": destFile, "type": type}, callback);
};
}
@ -82,21 +77,18 @@ else
var firstPrompt = true;
//append error messages to the buffer
abiword.stderr.on('data', function (data)
{
abiword.stderr.on('data', function (data) {
stdoutBuffer += data.toString();
});
//abiword died, let's restart abiword and return an error with the callback
abiword.on('exit', function (code)
{
abiword.on('exit', function (code) {
spawnAbiword();
stdoutCallback(`Abiword died with exit code ${code}`);
});
//delegate the processing of stdout to a other function
abiword.stdout.on('data',function (data)
{
abiword.stdout.on('data',function (data) {
//add data to buffer
stdoutBuffer+=data.toString();
@ -123,12 +115,10 @@ else
};
spawnAbiword();
doConvertTask = function(task, callback)
{
doConvertTask = function(task, callback) {
abiword.stdin.write("convert " + task.srcFile + " " + task.destFile + " " + task.type + "\n");
//create a callback that calls the task callback and the caller callback
stdoutCallback = function (err)
{
stdoutCallback = function (err) {
callback();
console.log("queue continue");
try{
@ -141,8 +131,7 @@ else
//Queue with the converts we have to do
var queue = async.queue(doConvertTask, 1);
exports.convertFile = function(srcFile, destFile, type, callback)
{
exports.convertFile = function(srcFile, destFile, type, callback) {
queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback});
};
}

View file

@ -23,8 +23,7 @@ var eejs = require('ep_etherpad-lite/node/eejs');
var _analyzeLine = require('./ExportHelper')._analyzeLine;
var _encodeWhitespace = require('./ExportHelper')._encodeWhitespace;
async function getPadHTML(pad, revNum)
{
async function getPadHTML(pad, revNum) {
let atext = pad.atext;
// fetch revision atext
@ -39,8 +38,7 @@ async function getPadHTML(pad, revNum)
exports.getPadHTML = getPadHTML;
exports.getHTMLFromAtext = getHTMLFromAtext;
async function getHTMLFromAtext(pad, atext, authorColors)
{
async function getHTMLFromAtext(pad, atext, authorColors) {
var apool = pad.apool();
var textLines = atext.text.slice(0, -1).split('\n');
var attribLines = Changeset.splitAttributionLines(atext.attribs, atext.text);
@ -110,8 +108,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
// iterates over all props(h1,h2,strong,...), checks if it is used in
// this pad, and if yes puts its attrib id->props value into anumMap
props.forEach(function (propName, i)
{
props.forEach(function (propName, i) {
var attrib = [propName, true];
if (_.isArray(propName)) {
// propName can be in the form of ['color', 'red'],
@ -125,8 +122,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
}
});
function getLineHTML(text, attribs)
{
function getLineHTML(text, attribs) {
// Use order of tags (b/i/u) as order of nesting, for simplicity
// and decent nesting. For example,
// <b>Just bold<b> <b><i>Bold and italics</i></b> <i>Just italics</i>
@ -166,8 +162,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
return _.isArray(property);
}
function emitOpenTag(i)
{
function emitOpenTag(i) {
openTags.unshift(i);
var spanClass = getSpanClassFor(i);
@ -183,8 +178,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
}
// this closes an open tag and removes its reference from openTags
function emitCloseTag(i)
{
function emitCloseTag(i) {
openTags.shift();
var spanClass = getSpanClassFor(i);
var spanWithData = isSpanWithData(i);
@ -202,8 +196,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
var idx = 0;
function processNextChars(numChars)
{
function processNextChars(numChars) {
if (numChars <= 0)
{
return;
@ -220,8 +213,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
var usedAttribs = [];
// mark all attribs as used
Changeset.eachAttribNumber(o.attribs, function (a)
{
Changeset.eachAttribNumber(o.attribs, function (a) {
if (a in anumMap)
{
usedAttribs.push(anumMap[a]); // i = 0 => bold, etc.
@ -280,8 +272,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
} // end processNextChars
if (urls)
{
urls.forEach(function (urlData)
{
urls.forEach(function (urlData) {
var startIndex = urlData[0];
var url = urlData[1];
var urlLength = url.length;
@ -341,8 +332,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
//To create list parent elements
if ((!prevLine || prevLine.listLevel !== line.listLevel) || (prevLine && line.listTypeName !== prevLine.listTypeName))
{
var exists = _.find(openLists, function (item)
{
var exists = _.find(openLists, function (item) {
return (item.level === line.listLevel && item.type === line.listTypeName);
});
if (!exists) {
@ -445,8 +435,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
for (var diff = nextLevel; diff < line.listLevel; diff++)
{
openLists = openLists.filter(function(el)
{
openLists = openLists.filter(function(el) {
return el.level !== diff && el.type !== line.listTypeName;
});
@ -485,8 +474,7 @@ async function getHTMLFromAtext(pad, atext, authorColors)
return pieces.join('');
}
exports.getPadHTMLDocument = async function (padId, revNum)
{
exports.getPadHTMLDocument = async function (padId, revNum) {
let pad = await padManager.getPad(padId);
// Include some Styles into the Head for Export
@ -518,8 +506,7 @@ var _REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|g
// returns null if no URLs, or [[startIndex1, url1], [startIndex2, url2], ...]
function _findURLs(text)
{
function _findURLs(text) {
_REGEX_URL.lastIndex = 0;
var urls = null;
var execResult;

View file

@ -23,8 +23,7 @@ var padManager = require("../db/PadManager");
var _analyzeLine = require('./ExportHelper')._analyzeLine;
// This is slightly different than the HTML method as it passes the output to getTXTFromAText
var getPadTXT = async function(pad, revNum)
{
var getPadTXT = async function(pad, revNum) {
let atext = pad.atext;
if (revNum != undefined) {
@ -38,8 +37,7 @@ var getPadTXT = async function(pad, revNum)
// This is different than the functionality provided in ExportHtml as it provides formatting
// functionality that is designed specifically for TXT exports
function getTXTFromAtext(pad, atext, authorColors)
{
function getTXTFromAtext(pad, atext, authorColors) {
var apool = pad.apool();
var textLines = atext.text.slice(0, -1).split('\n');
var attribLines = Changeset.splitAttributionLines(atext.attribs, atext.text);
@ -259,8 +257,7 @@ function getTXTFromAtext(pad, atext, authorColors)
exports.getTXTFromAtext = getTXTFromAtext;
exports.getPadTXTDocument = async function(padId, revNum)
{
exports.getPadTXTDocument = async function(padId, revNum) {
let pad = await padManager.getPad(padId);
return getPadTXT(pad, revNum);
}

View file

@ -18,8 +18,7 @@ var log4js = require('log4js');
const db = require("../db/DB");
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
exports.setPadRaw = function(padId, records)
{
exports.setPadRaw = function(padId, records) {
records = JSON.parse(records);
Object.keys(records).forEach(async function(key) {

View file

@ -145,8 +145,7 @@ function requestURIs(locations, method, headers, callback) {
* @param req the Express request
* @param res the Express response
*/
function minify(req, res)
{
function minify(req, res) {
var filename = req.params['filename'];
// No relative paths, especially if they may go up the file hierarchy.
@ -318,22 +317,18 @@ function lastModifiedDateOfEverything(callback) {
var folders2check = [ROOT_DIR + 'js/', ROOT_DIR + 'css/'];
var latestModification = 0;
//go trough this two folders
async.forEach(folders2check, function(path, callback)
{
async.forEach(folders2check, function(path, callback) {
//read the files in the folder
fs.readdir(path, function(err, files)
{
fs.readdir(path, function(err, files) {
if(ERR(err, callback)) return;
//we wanna check the directory itself for changes too
files.push(".");
//go trough all files in this folder
async.forEach(files, function(filename, callback)
{
async.forEach(files, function(filename, callback) {
//get the stat data of this file
fs.stat(path + "/" + filename, function(err, stats)
{
fs.stat(path + "/" + filename, function(err, stats) {
if(ERR(err, callback)) return;
//get the modification time

View file

@ -7,13 +7,11 @@ var Terser = require("terser");
var path = require('path');
var Threads = require('threads')
function compressJS(content)
{
function compressJS(content) {
return Terser.minify(content);
}
function compressCSS(filename, ROOT_DIR)
{
function compressCSS(filename, ROOT_DIR) {
return new Promise((res, rej) => {
try {
const absPath = path.join(ROOT_DIR, filename);

View file

@ -381,8 +381,7 @@ exports.commitRateLimiting = {
exports.importMaxFileSize = 50 * 1024 * 1024;
// checks if abiword is avaiable
exports.abiwordAvailable = function()
{
exports.abiwordAvailable = function() {
if (exports.abiword != null) {
return os.type().indexOf("Windows") != -1 ? "withoutPDF" : "yes";
} else {

View file

@ -3,8 +3,7 @@
*/
var crypto = require('crypto');
var randomString = function(len)
{
var randomString = function(len) {
return crypto.randomBytes(len).toString('hex')
};