prepare to async: trivial reformatting

This change is only cosmetic. Its aim is do make it easier to understand the
async changes that are going to be merged later on. It was extracted from the
original work from Ray Bellis.

To verify that nothing has changed, you can run the following command on each
file touched by this commit:
  npm install uglify-es
  diff --unified <(uglify-js --beautify bracketize <BEFORE.js>) <(uglify-js --beautify bracketize <AFTER.js>)



This is a complete script that does the same automatically (works from a
mercurial clone):

```bash
#!/usr/bin/env bash

set -eu

REVISION=<THIS_REVISION>

PARENT_REV=$(hg identify --rev "${REVISION}" --template '{p1rev}')
FILE_LIST=$(hg status --no-status --change ${REVISION})
UGLIFYJS="node_modules/uglify-es/bin/uglifyjs"

for FILE_NAME in ${FILE_LIST[@]}; do
  echo "Checking ${FILE_NAME}"
  diff --unified \
    <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${PARENT_REV}" "${FILE_NAME}")) \
    <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${REVISION}"   "${FILE_NAME}"))
done
```
This commit is contained in:
muxator 2019-02-08 23:20:57 +01:00
parent cc23bd18a4
commit 9497ee734f
33 changed files with 2706 additions and 2943 deletions

View file

@ -18,25 +18,33 @@
* limitations under the License.
*/
var ERR = require("async-stacktrace");
var db = require("./DB").db;
var customError = require("../utils/customError");
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
exports.getColorPalette = function(){
return ["#ffc7c7", "#fff1c7", "#e3ffc7", "#c7ffd5", "#c7ffff", "#c7d5ff", "#e3c7ff", "#ffc7f1", "#ffa8a8", "#ffe699", "#cfff9e", "#99ffb3", "#a3ffff", "#99b3ff", "#cc99ff", "#ff99e5", "#e7b1b1", "#e9dcAf", "#cde9af", "#bfedcc", "#b1e7e7", "#c3cdee", "#d2b8ea", "#eec3e6", "#e9cece", "#e7e0ca", "#d3e5c7", "#bce1c5", "#c1e2e2", "#c1c9e2", "#cfc1e2", "#e0bdd9", "#baded3", "#a0f8eb", "#b1e7e0", "#c3c8e4", "#cec5e2", "#b1d5e7", "#cda8f0", "#f0f0a8", "#f2f2a6", "#f5a8eb", "#c5f9a9", "#ececbb", "#e7c4bc", "#daf0b2", "#b0a0fd", "#bce2e7", "#cce2bb", "#ec9afe", "#edabbd", "#aeaeea", "#c4e7b1", "#d722bb", "#f3a5e7", "#ffa8a8", "#d8c0c5", "#eaaedd", "#adc6eb", "#bedad1", "#dee9af", "#e9afc2", "#f8d2a0", "#b3b3e6"];
exports.getColorPalette = function() {
return [
"#ffc7c7", "#fff1c7", "#e3ffc7", "#c7ffd5", "#c7ffff", "#c7d5ff", "#e3c7ff", "#ffc7f1",
"#ffa8a8", "#ffe699", "#cfff9e", "#99ffb3", "#a3ffff", "#99b3ff", "#cc99ff", "#ff99e5",
"#e7b1b1", "#e9dcAf", "#cde9af", "#bfedcc", "#b1e7e7", "#c3cdee", "#d2b8ea", "#eec3e6",
"#e9cece", "#e7e0ca", "#d3e5c7", "#bce1c5", "#c1e2e2", "#c1c9e2", "#cfc1e2", "#e0bdd9",
"#baded3", "#a0f8eb", "#b1e7e0", "#c3c8e4", "#cec5e2", "#b1d5e7", "#cda8f0", "#f0f0a8",
"#f2f2a6", "#f5a8eb", "#c5f9a9", "#ececbb", "#e7c4bc", "#daf0b2", "#b0a0fd", "#bce2e7",
"#cce2bb", "#ec9afe", "#edabbd", "#aeaeea", "#c4e7b1", "#d722bb", "#f3a5e7", "#ffa8a8",
"#d8c0c5", "#eaaedd", "#adc6eb", "#bedad1", "#dee9af", "#e9afc2", "#f8d2a0", "#b3b3e6"
];
};
/**
* Checks if the author exists
*/
exports.doesAuthorExists = function (authorID, callback)
exports.doesAuthorExists = function(authorID, callback)
{
//check if the database entry of this author exists
db.get("globalAuthor:" + authorID, function (err, author)
{
if(ERR(err, callback)) return;
// check if the database entry of this author exists
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err, callback)) return;
callback(null, author != null);
});
}
@ -46,12 +54,12 @@ exports.doesAuthorExists = function (authorID, callback)
* @param {String} token The token
* @param {Function} callback callback (err, author)
*/
exports.getAuthor4Token = function (token, callback)
exports.getAuthor4Token = function(token, callback)
{
mapAuthorWithDBKey("token2author", token, function(err, author)
{
if(ERR(err, callback)) return;
//return only the sub value authorID
mapAuthorWithDBKey("token2author", token, function(err, author) {
if (ERR(err, callback)) return;
// return only the sub value authorID
callback(null, author ? author.authorID : author);
});
}
@ -62,17 +70,17 @@ exports.getAuthor4Token = function (token, callback)
* @param {String} name The name of the author (optional)
* @param {Function} callback callback (err, author)
*/
exports.createAuthorIfNotExistsFor = function (authorMapper, name, callback)
exports.createAuthorIfNotExistsFor = function(authorMapper, name, callback)
{
mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author)
{
if(ERR(err, callback)) return;
mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author) {
if (ERR(err, callback)) return;
//set the name of this author
if(name)
if (name) {
// set the name of this author
exports.setAuthorName(author.authorID, name);
}
//return the authorID
// return the authorID
callback(null, author);
});
}
@ -86,33 +94,30 @@ exports.createAuthorIfNotExistsFor = function (authorMapper, name, callback)
*/
function mapAuthorWithDBKey (mapperkey, mapper, callback)
{
//try to map to an author
db.get(mapperkey + ":" + mapper, function (err, author)
{
if(ERR(err, callback)) return;
// try to map to an author
db.get(mapperkey + ":" + mapper, function(err, author) {
if (ERR(err, callback)) return;
//there is no author with this mapper, so create one
if(author == null)
{
exports.createAuthor(null, function(err, author)
{
if(ERR(err, callback)) return;
if (author == null) {
// there is no author with this mapper, so create one
exports.createAuthor(null, function(err, author) {
if (ERR(err, callback)) return;
//create the token2author relation
// create the token2author relation
db.set(mapperkey + ":" + mapper, author.authorID);
//return the author
// return the author
callback(null, author);
});
return;
}
//there is a author with this mapper
//update the timestamp of this author
// there is an author with this mapper
// update the timestamp of this author
db.setSub("globalAuthor:" + author, ["timestamp"], Date.now());
//return the author
// return the author
callback(null, {authorID: author});
});
}
@ -123,13 +128,17 @@ function mapAuthorWithDBKey (mapperkey, mapper, callback)
*/
exports.createAuthor = function(name, callback)
{
//create the new author name
// create the new author name
var author = "a." + randomString(16);
//create the globalAuthors db entry
var authorObj = {"colorId" : Math.floor(Math.random()*(exports.getColorPalette().length)), "name": name, "timestamp": Date.now()};
// create the globalAuthors db entry
var authorObj = {
"colorId": Math.floor(Math.random() * (exports.getColorPalette().length)),
"name": name,
"timestamp": Date.now()
};
//set the global author db entry
// set the global author db entry
db.set("globalAuthor:" + author, authorObj);
callback(null, {authorID: author});
@ -140,19 +149,17 @@ exports.createAuthor = function(name, callback)
* @param {String} author The id of the author
* @param {Function} callback callback(err, authorObj)
*/
exports.getAuthor = function (author, callback)
exports.getAuthor = function(author, callback)
{
db.get("globalAuthor:" + author, callback);
}
/**
* Returns the color Id of the author
* @param {String} author The id of the author
* @param {Function} callback callback(err, colorId)
*/
exports.getAuthorColorId = function (author, callback)
exports.getAuthorColorId = function(author, callback)
{
db.getSub("globalAuthor:" + author, ["colorId"], callback);
}
@ -163,7 +170,7 @@ exports.getAuthorColorId = function (author, callback)
* @param {String} colorId The color id of the author
* @param {Function} callback (optional)
*/
exports.setAuthorColorId = function (author, colorId, callback)
exports.setAuthorColorId = function(author, colorId, callback)
{
db.setSub("globalAuthor:" + author, ["colorId"], colorId, callback);
}
@ -173,7 +180,7 @@ exports.setAuthorColorId = function (author, colorId, callback)
* @param {String} author The id of the author
* @param {Function} callback callback(err, name)
*/
exports.getAuthorName = function (author, callback)
exports.getAuthorName = function(author, callback)
{
db.getSub("globalAuthor:" + author, ["name"], callback);
}
@ -184,7 +191,7 @@ exports.getAuthorName = function (author, callback)
* @param {String} name The name of the author
* @param {Function} callback (optional)
*/
exports.setAuthorName = function (author, name, callback)
exports.setAuthorName = function(author, name, callback)
{
db.setSub("globalAuthor:" + author, ["name"], name, callback);
}
@ -194,33 +201,33 @@ exports.setAuthorName = function (author, name, callback)
* @param {String} author The id of the author
* @param {Function} callback (optional)
*/
exports.listPadsOfAuthor = function (authorID, callback)
exports.listPadsOfAuthor = function(authorID, callback)
{
/* 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
*/
//get the globalAuthor
db.get("globalAuthor:" + authorID, function(err, author)
{
if(ERR(err, callback)) return;
//author does not exists
if(author == null)
{
callback(new customError("authorID does not exist","apierror"))
// get the globalAuthor
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err, callback)) return;
if (author == null) {
// author does not exist
callback(new customError("authorID does not exist", "apierror"));
return;
}
//everything is fine, return the pad IDs
// everything is fine, return the pad IDs
var pads = [];
if(author.padIDs != null)
{
for (var padId in author.padIDs)
{
if (author.padIDs != null) {
for (var padId in author.padIDs) {
pads.push(padId);
}
}
callback(null, {padIDs: pads});
});
}
@ -230,24 +237,22 @@ exports.listPadsOfAuthor = function (authorID, callback)
* @param {String} author The id of the author
* @param {String} padID The id of the pad the author contributes to
*/
exports.addPad = function (authorID, padID)
exports.addPad = function(authorID, padID)
{
//get the entry
db.get("globalAuthor:" + authorID, function(err, author)
{
if(ERR(err)) return;
if(author == null) return;
// get the entry
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err)) return;
if (author == null) return;
//the entry doesn't exist so far, let's create it
if(author.padIDs == null)
{
if (author.padIDs == null) {
// the entry doesn't exist so far, let's create it
author.padIDs = {};
}
//add the entry for this pad
author.padIDs[padID] = 1;// anything, because value is not used
// add the entry for this pad
author.padIDs[padID] = 1; // anything, because value is not used
//save the new element back
// save the new element back
db.set("globalAuthor:" + authorID, author);
});
}
@ -257,16 +262,14 @@ exports.addPad = 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 = function (authorID, padID)
exports.removePad = function(authorID, padID)
{
db.get("globalAuthor:" + authorID, function (err, author)
{
if(ERR(err)) return;
if(author == null) return;
db.get("globalAuthor:" + authorID, function(err, author) {
if (ERR(err)) return;
if (author == null) return;
if(author.padIDs != null)
{
//remove pad from author
if (author.padIDs != null) {
// remove pad from author
delete author.padIDs[padID];
db.set("globalAuthor:" + authorID, author);
}