mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
lint: Run eslint --fix
on src/
This commit is contained in:
parent
b8d07a42eb
commit
8e5fd19db2
109 changed files with 9061 additions and 10572 deletions
|
@ -18,19 +18,19 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
||||
var customError = require("../utils/customError");
|
||||
var padManager = require("./PadManager");
|
||||
var padMessageHandler = require("../handler/PadMessageHandler");
|
||||
var readOnlyManager = require("./ReadOnlyManager");
|
||||
var groupManager = require("./GroupManager");
|
||||
var authorManager = require("./AuthorManager");
|
||||
var sessionManager = require("./SessionManager");
|
||||
var exportHtml = require("../utils/ExportHtml");
|
||||
var exportTxt = require("../utils/ExportTxt");
|
||||
var importHtml = require("../utils/ImportHtml");
|
||||
var cleanText = require("./Pad").cleanText;
|
||||
var PadDiff = require("../utils/padDiff");
|
||||
const Changeset = require('ep_etherpad-lite/static/js/Changeset');
|
||||
const customError = require('../utils/customError');
|
||||
const padManager = require('./PadManager');
|
||||
const padMessageHandler = require('../handler/PadMessageHandler');
|
||||
const readOnlyManager = require('./ReadOnlyManager');
|
||||
const groupManager = require('./GroupManager');
|
||||
const authorManager = require('./AuthorManager');
|
||||
const sessionManager = require('./SessionManager');
|
||||
const exportHtml = require('../utils/ExportHtml');
|
||||
const exportTxt = require('../utils/ExportTxt');
|
||||
const importHtml = require('../utils/ImportHtml');
|
||||
const cleanText = require('./Pad').cleanText;
|
||||
const PadDiff = require('../utils/padDiff');
|
||||
|
||||
/* ********************
|
||||
* GROUP FUNCTIONS ****
|
||||
|
@ -101,10 +101,10 @@ Example returns:
|
|||
}
|
||||
|
||||
*/
|
||||
exports.getAttributePool = async function(padID) {
|
||||
let pad = await getPadSafe(padID, true);
|
||||
return { pool: pad.pool };
|
||||
}
|
||||
exports.getAttributePool = async function (padID) {
|
||||
const pad = await getPadSafe(padID, true);
|
||||
return {pool: pad.pool};
|
||||
};
|
||||
|
||||
/**
|
||||
getRevisionChangeset (padID, [rev])
|
||||
|
@ -119,22 +119,21 @@ 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);
|
||||
}
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
let head = pad.getHeadRevisionNumber();
|
||||
const pad = await getPadSafe(padID, true);
|
||||
const head = pad.getHeadRevisionNumber();
|
||||
|
||||
// the client asked for a special revision
|
||||
if (rev !== undefined) {
|
||||
|
||||
// check if this is a valid revision
|
||||
if (rev > head) {
|
||||
throw new customError("rev is higher than the head revision of the pad", "apierror");
|
||||
throw new customError('rev is higher than the head revision of the pad', 'apierror');
|
||||
}
|
||||
|
||||
// get the changeset for this revision
|
||||
|
@ -143,7 +142,7 @@ exports.getRevisionChangeset = async function(padID, rev) {
|
|||
|
||||
// the client wants the latest changeset, lets return it to him
|
||||
return pad.getRevisionChangeset(head);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
getText(padID, [rev]) returns the text of a pad
|
||||
|
@ -153,33 +152,32 @@ 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);
|
||||
}
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
let head = pad.getHeadRevisionNumber();
|
||||
const pad = await getPadSafe(padID, true);
|
||||
const head = pad.getHeadRevisionNumber();
|
||||
|
||||
// the client asked for a special revision
|
||||
if (rev !== undefined) {
|
||||
|
||||
// check if this is a valid revision
|
||||
if (rev > head) {
|
||||
throw new customError("rev is higher than the head revision of the pad", "apierror");
|
||||
throw new customError('rev is higher than the head revision of the pad', 'apierror');
|
||||
}
|
||||
|
||||
// get the text of this revision
|
||||
let text = await pad.getInternalRevisionAText(rev);
|
||||
return { text };
|
||||
const text = await pad.getInternalRevisionAText(rev);
|
||||
return {text};
|
||||
}
|
||||
|
||||
// the client wants the latest text, lets return it to him
|
||||
let text = exportTxt.getTXTFromAtext(pad, pad.atext);
|
||||
return { text };
|
||||
}
|
||||
const text = exportTxt.getTXTFromAtext(pad, pad.atext);
|
||||
return {text};
|
||||
};
|
||||
|
||||
/**
|
||||
setText(padID, text) sets the text of a pad
|
||||
|
@ -190,20 +188,20 @@ 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");
|
||||
if (typeof text !== 'string') {
|
||||
throw new customError('text is not a string', 'apierror');
|
||||
}
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
|
||||
await Promise.all([
|
||||
pad.setText(text),
|
||||
padMessageHandler.updatePadClients(pad),
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
appendText(padID, text) appends text to a pad
|
||||
|
@ -214,18 +212,18 @@ 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");
|
||||
if (typeof text !== 'string') {
|
||||
throw new customError('text is not a string', 'apierror');
|
||||
}
|
||||
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
await Promise.all([
|
||||
pad.appendText(text),
|
||||
padMessageHandler.updatePadClients(pad),
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
getHTML(padID, [rev]) returns the html of a pad
|
||||
|
@ -235,19 +233,19 @@ 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);
|
||||
}
|
||||
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
|
||||
// the client asked for a special revision
|
||||
if (rev !== undefined) {
|
||||
// check if this is a valid revision
|
||||
let head = pad.getHeadRevisionNumber();
|
||||
const head = pad.getHeadRevisionNumber();
|
||||
if (rev > head) {
|
||||
throw new customError("rev is higher than the head revision of the pad", "apierror");
|
||||
throw new customError('rev is higher than the head revision of the pad', 'apierror');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,9 +253,9 @@ exports.getHTML = async function(padID, rev) {
|
|||
let html = await exportHtml.getPadHTML(pad, rev);
|
||||
|
||||
// wrap the HTML
|
||||
html = "<!DOCTYPE HTML><html><body>" + html + "</body></html>";
|
||||
return { html };
|
||||
}
|
||||
html = `<!DOCTYPE HTML><html><body>${html}</body></html>`;
|
||||
return {html};
|
||||
};
|
||||
|
||||
/**
|
||||
setHTML(padID, html) sets the text of a pad based on HTML
|
||||
|
@ -267,20 +265,20 @@ 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");
|
||||
if (typeof html !== 'string') {
|
||||
throw new customError('html is not a string', 'apierror');
|
||||
}
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
|
||||
// add a new changeset with the new html to the pad
|
||||
try {
|
||||
await importHtml.setPadHTML(pad, cleanText(html));
|
||||
} catch (e) {
|
||||
throw new customError("HTML is malformed", "apierror");
|
||||
throw new customError('HTML is malformed', 'apierror');
|
||||
}
|
||||
|
||||
// update the clients on the pad
|
||||
|
@ -303,23 +301,23 @@ 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");
|
||||
throw new customError('start is below zero', 'apierror');
|
||||
}
|
||||
if (end < 0) {
|
||||
throw new customError("end is below zero", "apierror");
|
||||
throw new customError('end is below zero', 'apierror');
|
||||
}
|
||||
if (start > end) {
|
||||
throw new customError("start is higher than end", "apierror");
|
||||
throw new customError('start is higher than end', 'apierror');
|
||||
}
|
||||
}
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
|
||||
var chatHead = pad.chatHead;
|
||||
const chatHead = pad.chatHead;
|
||||
|
||||
// fall back to getting the whole chat-history if a parameter is missing
|
||||
if (!start || !end) {
|
||||
|
@ -328,17 +326,17 @@ exports.getChatHistory = async function(padID, start, end) {
|
|||
}
|
||||
|
||||
if (start > chatHead) {
|
||||
throw new customError("start is higher than the current chatHead", "apierror");
|
||||
throw new customError('start is higher than the current chatHead', 'apierror');
|
||||
}
|
||||
if (end > chatHead) {
|
||||
throw new customError("end is higher than the current chatHead", "apierror");
|
||||
throw new customError('end is higher than the current chatHead', 'apierror');
|
||||
}
|
||||
|
||||
// the the whole message-log and return it to the client
|
||||
let messages = await pad.getChatMessages(start, end);
|
||||
const messages = await pad.getChatMessages(start, end);
|
||||
|
||||
return { messages };
|
||||
}
|
||||
return {messages};
|
||||
};
|
||||
|
||||
/**
|
||||
appendChatMessage(padID, text, authorID, time), creates a chat message for the pad id, time is a timestamp
|
||||
|
@ -348,10 +346,10 @@ 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");
|
||||
if (typeof text !== 'string') {
|
||||
throw new customError('text is not a string', 'apierror');
|
||||
}
|
||||
|
||||
// if time is not an integer value set time to current timestamp
|
||||
|
@ -363,7 +361,7 @@ exports.appendChatMessage = async function(padID, text, authorID, time) {
|
|||
|
||||
// save chat message to database and send message to all connected clients
|
||||
await padMessageHandler.sendChatMessageToPadClients(time, authorID, text, padID);
|
||||
}
|
||||
};
|
||||
|
||||
/* ***************
|
||||
* PAD FUNCTIONS *
|
||||
|
@ -377,11 +375,11 @@ 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() };
|
||||
}
|
||||
const pad = await getPadSafe(padID, true);
|
||||
return {revisions: pad.getHeadRevisionNumber()};
|
||||
};
|
||||
|
||||
/**
|
||||
getSavedRevisionsCount(padID) returns the number of saved revisions of this pad
|
||||
|
@ -391,11 +389,11 @@ 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() };
|
||||
}
|
||||
const pad = await getPadSafe(padID, true);
|
||||
return {savedRevisions: pad.getSavedRevisionsNumber()};
|
||||
};
|
||||
|
||||
/**
|
||||
listSavedRevisions(padID) returns the list of saved revisions of this pad
|
||||
|
@ -405,11 +403,11 @@ 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() };
|
||||
}
|
||||
const pad = await getPadSafe(padID, true);
|
||||
return {savedRevisions: pad.getSavedRevisionsList()};
|
||||
};
|
||||
|
||||
/**
|
||||
saveRevision(padID) returns the list of saved revisions of this pad
|
||||
|
@ -419,28 +417,28 @@ 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);
|
||||
}
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
let head = pad.getHeadRevisionNumber();
|
||||
const pad = await getPadSafe(padID, true);
|
||||
const head = pad.getHeadRevisionNumber();
|
||||
|
||||
// the client asked for a special revision
|
||||
if (rev !== undefined) {
|
||||
if (rev > head) {
|
||||
throw new customError("rev is higher than the head revision of the pad", "apierror");
|
||||
throw new customError('rev is higher than the head revision of the pad', 'apierror');
|
||||
}
|
||||
} else {
|
||||
rev = pad.getHeadRevisionNumber();
|
||||
}
|
||||
|
||||
let author = await authorManager.createAuthor('API');
|
||||
const author = await authorManager.createAuthor('API');
|
||||
await pad.addSavedRevision(rev, author.authorID, 'Saved through API call');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
getLastEdited(padID) returns the timestamp of the last revision of the pad
|
||||
|
@ -450,12 +448,12 @@ 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();
|
||||
return { lastEdited };
|
||||
}
|
||||
const pad = await getPadSafe(padID, true);
|
||||
const lastEdited = await pad.getLastEdit();
|
||||
return {lastEdited};
|
||||
};
|
||||
|
||||
/**
|
||||
createPad(padName [, text]) creates a new pad in this group
|
||||
|
@ -465,22 +463,22 @@ 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) {
|
||||
throw new customError("createPad can't create group pads", "apierror");
|
||||
if (padID.indexOf('$') !== -1) {
|
||||
throw new customError("createPad can't create group pads", 'apierror');
|
||||
}
|
||||
|
||||
// check for url special characters
|
||||
if (padID.match(/(\/|\?|&|#)/)) {
|
||||
throw new customError("malformed padID: Remove special characters", "apierror");
|
||||
throw new customError('malformed padID: Remove special characters', 'apierror');
|
||||
}
|
||||
}
|
||||
|
||||
// create pad
|
||||
await getPadSafe(padID, false, text);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
deletePad(padID) deletes a pad
|
||||
|
@ -490,10 +488,10 @@ Example returns:
|
|||
{code: 0, message:"ok", data: null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.deletePad = async function(padID) {
|
||||
let pad = await getPadSafe(padID, true);
|
||||
exports.deletePad = async function (padID) {
|
||||
const pad = await getPadSafe(padID, true);
|
||||
await pad.remove();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
restoreRevision(padID, [rev]) Restores revision from past as new changeset
|
||||
|
@ -503,34 +501,34 @@ 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");
|
||||
throw new customError('rev is not defined', 'apierror');
|
||||
}
|
||||
rev = checkValidRev(rev);
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
|
||||
// check if this is a valid revision
|
||||
if (rev > pad.getHeadRevisionNumber()) {
|
||||
throw new customError("rev is higher than the head revision of the pad", "apierror");
|
||||
throw new customError('rev is higher than the head revision of the pad', 'apierror');
|
||||
}
|
||||
|
||||
let atext = await pad.getInternalRevisionAText(rev);
|
||||
const atext = await pad.getInternalRevisionAText(rev);
|
||||
|
||||
var oldText = pad.text();
|
||||
atext.text += "\n";
|
||||
const oldText = pad.text();
|
||||
atext.text += '\n';
|
||||
|
||||
function eachAttribRun(attribs, func) {
|
||||
var attribsIter = Changeset.opIterator(attribs);
|
||||
var textIndex = 0;
|
||||
var newTextStart = 0;
|
||||
var newTextEnd = atext.text.length;
|
||||
const attribsIter = Changeset.opIterator(attribs);
|
||||
let textIndex = 0;
|
||||
const newTextStart = 0;
|
||||
const newTextEnd = atext.text.length;
|
||||
while (attribsIter.hasNext()) {
|
||||
var op = attribsIter.next();
|
||||
var nextIndex = textIndex + op.chars;
|
||||
const op = attribsIter.next();
|
||||
const nextIndex = textIndex + op.chars;
|
||||
if (!(nextIndex <= newTextStart || textIndex >= newTextEnd)) {
|
||||
func(Math.max(newTextStart, textIndex), Math.min(newTextEnd, nextIndex), op.attribs);
|
||||
}
|
||||
|
@ -539,14 +537,14 @@ exports.restoreRevision = async function(padID, rev) {
|
|||
}
|
||||
|
||||
// create a new changeset with a helper builder object
|
||||
var builder = Changeset.builder(oldText.length);
|
||||
const builder = Changeset.builder(oldText.length);
|
||||
|
||||
// assemble each line into the builder
|
||||
eachAttribRun(atext.attribs, function(start, end, attribs) {
|
||||
eachAttribRun(atext.attribs, (start, end, attribs) => {
|
||||
builder.insert(atext.text.substring(start, end), attribs);
|
||||
});
|
||||
|
||||
var lastNewlinePos = oldText.lastIndexOf('\n');
|
||||
const lastNewlinePos = oldText.lastIndexOf('\n');
|
||||
if (lastNewlinePos < 0) {
|
||||
builder.remove(oldText.length - 1, 0);
|
||||
} else {
|
||||
|
@ -554,13 +552,13 @@ exports.restoreRevision = async function(padID, rev) {
|
|||
builder.remove(oldText.length - lastNewlinePos - 1, 0);
|
||||
}
|
||||
|
||||
var changeset = builder.toString();
|
||||
const changeset = builder.toString();
|
||||
|
||||
await Promise.all([
|
||||
pad.appendRevision(changeset),
|
||||
padMessageHandler.updatePadClients(pad),
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
copyPad(sourceID, destinationID[, force=false]) copies a pad. If force is true,
|
||||
|
@ -571,10 +569,10 @@ 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) {
|
||||
let pad = await getPadSafe(sourceID, true);
|
||||
exports.copyPad = async function (sourceID, destinationID, force) {
|
||||
const pad = await getPadSafe(sourceID, true);
|
||||
await pad.copy(destinationID, force);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
copyPadWithoutHistory(sourceID, destinationID[, force=false]) copies a pad. If force is true,
|
||||
|
@ -585,10 +583,10 @@ 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) {
|
||||
let pad = await getPadSafe(sourceID, true);
|
||||
exports.copyPadWithoutHistory = async function (sourceID, destinationID, force) {
|
||||
const pad = await getPadSafe(sourceID, true);
|
||||
await pad.copyPadWithoutHistory(destinationID, force);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
movePad(sourceID, destinationID[, force=false]) moves a pad. If force is true,
|
||||
|
@ -599,11 +597,11 @@ 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) {
|
||||
let pad = await getPadSafe(sourceID, true);
|
||||
exports.movePad = async function (sourceID, destinationID, force) {
|
||||
const pad = await getPadSafe(sourceID, true);
|
||||
await pad.copy(destinationID, force);
|
||||
await pad.remove();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
getReadOnlyLink(padID) returns the read only link of a pad
|
||||
|
@ -613,15 +611,15 @@ 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);
|
||||
|
||||
// get the readonlyId
|
||||
let readOnlyID = await readOnlyManager.getReadOnlyId(padID);
|
||||
const readOnlyID = await readOnlyManager.getReadOnlyId(padID);
|
||||
|
||||
return { readOnlyID };
|
||||
}
|
||||
return {readOnlyID};
|
||||
};
|
||||
|
||||
/**
|
||||
getPadID(roID) returns the padID of a pad based on the readonlyID(roID)
|
||||
|
@ -631,15 +629,15 @@ 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);
|
||||
const padID = await readOnlyManager.getPadId(roID);
|
||||
if (padID === null) {
|
||||
throw new customError("padID does not exist", "apierror");
|
||||
throw new customError('padID does not exist', 'apierror');
|
||||
}
|
||||
|
||||
return { padID };
|
||||
}
|
||||
return {padID};
|
||||
};
|
||||
|
||||
/**
|
||||
setPublicStatus(padID, publicStatus) sets a boolean for the public status of a pad
|
||||
|
@ -649,20 +647,20 @@ 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");
|
||||
checkGroupPad(padID, 'publicStatus');
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
|
||||
// convert string to boolean
|
||||
if (typeof publicStatus === "string") {
|
||||
publicStatus = (publicStatus.toLowerCase() === "true");
|
||||
if (typeof publicStatus === 'string') {
|
||||
publicStatus = (publicStatus.toLowerCase() === 'true');
|
||||
}
|
||||
|
||||
await pad.setPublicStatus(publicStatus);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
getPublicStatus(padID) return true of false
|
||||
|
@ -672,14 +670,14 @@ 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");
|
||||
checkGroupPad(padID, 'publicStatus');
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
return { publicStatus: pad.getPublicStatus() };
|
||||
}
|
||||
const pad = await getPadSafe(padID, true);
|
||||
return {publicStatus: pad.getPublicStatus()};
|
||||
};
|
||||
|
||||
/**
|
||||
listAuthorsOfPad(padID) returns an array of authors who contributed to this pad
|
||||
|
@ -689,12 +687,12 @@ 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();
|
||||
return { authorIDs };
|
||||
}
|
||||
const pad = await getPadSafe(padID, true);
|
||||
const authorIDs = pad.getAllAuthors();
|
||||
return {authorIDs};
|
||||
};
|
||||
|
||||
/**
|
||||
sendClientsMessage(padID, msg) sends a message to all clients connected to the
|
||||
|
@ -719,10 +717,10 @@ Example returns:
|
|||
{code: 1, message:"padID does not exist"}
|
||||
*/
|
||||
|
||||
exports.sendClientsMessage = async function(padID, msg) {
|
||||
let pad = await getPadSafe(padID, true);
|
||||
exports.sendClientsMessage = async function (padID, msg) {
|
||||
const pad = await getPadSafe(padID, true);
|
||||
padMessageHandler.handleCustomMessage(padID, msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
checkToken() returns ok when the current api token is valid
|
||||
|
@ -732,8 +730,8 @@ 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 () {
|
||||
};
|
||||
|
||||
/**
|
||||
getChatHead(padID) returns the chatHead (last number of the last chat-message) of the pad
|
||||
|
@ -743,11 +741,11 @@ 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 };
|
||||
}
|
||||
const pad = await getPadSafe(padID, true);
|
||||
return {chatHead: pad.chatHead};
|
||||
};
|
||||
|
||||
/**
|
||||
createDiffHTML(padID, startRev, endRev) returns an object of diffs from 2 points in a pad
|
||||
|
@ -757,8 +755,7 @@ Example returns:
|
|||
{"code":0,"message":"ok","data":{"html":"<style>\n.authora_HKIv23mEbachFYfH {background-color: #a979d9}\n.authora_n4gEeMLsv1GivNeh {background-color: #a9b5d9}\n.removed {text-decoration: line-through; -ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=80)'; filter: alpha(opacity=80); opacity: 0.8; }\n</style>Welcome to Etherpad!<br><br>This pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!<br><br>Get involved with Etherpad at <a href=\"http://etherpad.org\">http://etherpad.org</a><br><span class=\"authora_HKIv23mEbachFYfH\">aw</span><br><br>","authors":["a.HKIv23mEbachFYfH",""]}}
|
||||
{"code":4,"message":"no or wrong API Key","data":null}
|
||||
*/
|
||||
exports.createDiffHTML = async function(padID, startRev, endRev) {
|
||||
|
||||
exports.createDiffHTML = async function (padID, startRev, endRev) {
|
||||
// check if startRev is a number
|
||||
if (startRev !== undefined) {
|
||||
startRev = checkValidRev(startRev);
|
||||
|
@ -770,18 +767,18 @@ exports.createDiffHTML = async function(padID, startRev, endRev) {
|
|||
}
|
||||
|
||||
// get the pad
|
||||
let pad = await getPadSafe(padID, true);
|
||||
const pad = await getPadSafe(padID, true);
|
||||
try {
|
||||
var padDiff = new PadDiff(pad, startRev, endRev);
|
||||
} catch (e) {
|
||||
throw { stop: e.message };
|
||||
throw {stop: e.message};
|
||||
}
|
||||
|
||||
let html = await padDiff.getHtml();
|
||||
let authors = await padDiff.getAuthors();
|
||||
const html = await padDiff.getHtml();
|
||||
const authors = await padDiff.getAuthors();
|
||||
|
||||
return { html, authors };
|
||||
}
|
||||
return {html, authors};
|
||||
};
|
||||
|
||||
/* ********************
|
||||
** GLOBAL FUNCTIONS **
|
||||
|
@ -796,20 +793,20 @@ exports.createDiffHTML = async function(padID, startRev, endRev) {
|
|||
{"code":4,"message":"no or wrong API Key","data":null}
|
||||
*/
|
||||
|
||||
exports.getStats = async function() {
|
||||
exports.getStats = async function () {
|
||||
const sessionInfos = padMessageHandler.sessioninfos;
|
||||
|
||||
const sessionKeys = Object.keys(sessionInfos);
|
||||
const activePads = new Set(Object.entries(sessionInfos).map(k => k[1].padId));
|
||||
const activePads = new Set(Object.entries(sessionInfos).map((k) => k[1].padId));
|
||||
|
||||
const { padIDs } = await padManager.listAllPads();
|
||||
const {padIDs} = await padManager.listAllPads();
|
||||
|
||||
return {
|
||||
totalPads: padIDs.length,
|
||||
totalSessions: sessionKeys.length,
|
||||
totalActivePads: activePads.size,
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/* ****************************
|
||||
** INTERNAL HELPER FUNCTIONS *
|
||||
|
@ -817,32 +814,32 @@ exports.getStats = async function() {
|
|||
|
||||
// checks if a number is an int
|
||||
function is_int(value) {
|
||||
return (parseFloat(value) == parseInt(value, 10)) && !isNaN(value)
|
||||
return (parseFloat(value) == parseInt(value, 10)) && !isNaN(value);
|
||||
}
|
||||
|
||||
// gets a pad safe
|
||||
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");
|
||||
if (typeof padID !== 'string') {
|
||||
throw new customError('padID is not a string', 'apierror');
|
||||
}
|
||||
|
||||
// check if the padID maches the requirements
|
||||
if (!padManager.isValidPadId(padID)) {
|
||||
throw new customError("padID did not match requirements", "apierror");
|
||||
throw new customError('padID did not match requirements', 'apierror');
|
||||
}
|
||||
|
||||
// check if the pad exists
|
||||
let exists = await padManager.doesPadExists(padID);
|
||||
const exists = await padManager.doesPadExists(padID);
|
||||
|
||||
if (!exists && shouldExist) {
|
||||
// does not exist, but should
|
||||
throw new customError("padID does not exist", "apierror");
|
||||
throw new customError('padID does not exist', 'apierror');
|
||||
}
|
||||
|
||||
if (exists && !shouldExist) {
|
||||
// does exist, but shouldn't
|
||||
throw new customError("padID does already exist", "apierror");
|
||||
throw new customError('padID does already exist', 'apierror');
|
||||
}
|
||||
|
||||
// pad exists, let's get it
|
||||
|
@ -852,23 +849,23 @@ 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) {
|
||||
if (typeof rev !== "number") {
|
||||
if (typeof rev !== 'number') {
|
||||
rev = parseInt(rev, 10);
|
||||
}
|
||||
|
||||
// check if rev is a number
|
||||
if (isNaN(rev)) {
|
||||
throw new customError("rev is not a number", "apierror");
|
||||
throw new customError('rev is not a number', 'apierror');
|
||||
}
|
||||
|
||||
// ensure this is not a negative number
|
||||
if (rev < 0) {
|
||||
throw new customError("rev is not a negative number", "apierror");
|
||||
throw new customError('rev is not a negative number', 'apierror');
|
||||
}
|
||||
|
||||
// ensure this is not a float value
|
||||
if (!is_int(rev)) {
|
||||
throw new customError("rev is a float value", "apierror");
|
||||
throw new customError('rev is a float value', 'apierror');
|
||||
}
|
||||
|
||||
return rev;
|
||||
|
@ -877,7 +874,7 @@ function checkValidRev(rev) {
|
|||
// checks if a padID is part of a group
|
||||
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");
|
||||
if (padID && padID.indexOf('$') === -1) {
|
||||
throw new customError(`You can only get/set the ${field} of pads that belong to a group`, 'apierror');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue