mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
lint: src/node/db/PadManager.js
This commit is contained in:
parent
f0c26c9ba2
commit
e06b9442e0
1 changed files with 10 additions and 11 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* The Pad Manager is a Factory for pad Objects
|
* The Pad Manager is a Factory for pad Objects
|
||||||
*/
|
*/
|
||||||
|
@ -18,7 +19,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const customError = require('../utils/customError');
|
const CustomError = require('../utils/customError');
|
||||||
const Pad = require('../db/Pad').Pad;
|
const Pad = require('../db/Pad').Pad;
|
||||||
const db = require('./DB');
|
const db = require('./DB');
|
||||||
|
|
||||||
|
@ -109,22 +110,22 @@ const padList = {
|
||||||
* @param id A String with the id of the pad
|
* @param id A String with the id of the pad
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
exports.getPad = async function (id, text) {
|
exports.getPad = async (id, text) => {
|
||||||
// check if this is a valid padId
|
// check if this is a valid padId
|
||||||
if (!exports.isValidPadId(id)) {
|
if (!exports.isValidPadId(id)) {
|
||||||
throw new customError(`${id} is not a valid padId`, 'apierror');
|
throw new CustomError(`${id} is not a valid padId`, 'apierror');
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this is a valid text
|
// check if this is a valid text
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
// check if text is a string
|
// check if text is a string
|
||||||
if (typeof text !== 'string') {
|
if (typeof text !== 'string') {
|
||||||
throw new customError('text is not a string', 'apierror');
|
throw new CustomError('text is not a string', 'apierror');
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if text is less than 100k chars
|
// check if text is less than 100k chars
|
||||||
if (text.length > 100000) {
|
if (text.length > 100000) {
|
||||||
throw new customError('text must be less than 100k chars', 'apierror');
|
throw new CustomError('text must be less than 100k chars', 'apierror');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,14 +147,14 @@ exports.getPad = async function (id, text) {
|
||||||
return pad;
|
return pad;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.listAllPads = async function () {
|
exports.listAllPads = async () => {
|
||||||
const padIDs = await padList.getPads();
|
const padIDs = await padList.getPads();
|
||||||
|
|
||||||
return {padIDs};
|
return {padIDs};
|
||||||
};
|
};
|
||||||
|
|
||||||
// checks if a pad exists
|
// checks if a pad exists
|
||||||
exports.doesPadExist = async function (padId) {
|
exports.doesPadExist = async (padId) => {
|
||||||
const value = await db.get(`pad:${padId}`);
|
const value = await db.get(`pad:${padId}`);
|
||||||
|
|
||||||
return (value != null && value.atext);
|
return (value != null && value.atext);
|
||||||
|
@ -189,9 +190,7 @@ exports.sanitizePadId = async function sanitizePadId(padId) {
|
||||||
return padId;
|
return padId;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.isValidPadId = function (padId) {
|
exports.isValidPadId = (padId) => /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId);
|
||||||
return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the pad from database and unloads it.
|
* Removes the pad from database and unloads it.
|
||||||
|
@ -204,6 +203,6 @@ exports.removePad = async (padId) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// removes a pad from the cache
|
// removes a pad from the cache
|
||||||
exports.unloadPad = function (padId) {
|
exports.unloadPad = (padId) => {
|
||||||
globalPads.remove(padId);
|
globalPads.remove(padId);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue