lint: Fix some straightforward ESLint errors

This commit is contained in:
Richard Hansen 2020-12-08 03:20:59 -05:00
parent ac086c7925
commit ff19181cd1
10 changed files with 154 additions and 153 deletions

View file

@ -1,3 +1,5 @@
'use strict';
/** /**
* The DB Module provides a database initalized with the settings * The DB Module provides a database initalized with the settings
* provided by the settings module * provided by the settings module
@ -25,7 +27,8 @@ const log4js = require('log4js');
const util = require('util'); const util = require('util');
// set database settings // set database settings
const db = new ueberDB.database(settings.dbType, settings.dbSettings, null, log4js.getLogger('ueberDB')); const db =
new ueberDB.database(settings.dbType, settings.dbSettings, null, log4js.getLogger('ueberDB'));
/** /**
* The UeberDB Object that provides the database functions * The UeberDB Object that provides the database functions
@ -36,41 +39,38 @@ exports.db = null;
* Initalizes the database with the settings provided by the settings module * Initalizes the database with the settings provided by the settings module
* @param {Function} callback * @param {Function} callback
*/ */
exports.init = function () { exports.init = async () => await new Promise((resolve, reject) => {
// initalize the database async db.init((err) => {
return new Promise((resolve, reject) => { if (err) {
db.init((err) => { // there was an error while initializing the database, output it and stop
if (err) { console.error('ERROR: Problem while initalizing the database');
// there was an error while initializing the database, output it and stop console.error(err.stack ? err.stack : err);
console.error('ERROR: Problem while initalizing the database'); process.exit(1);
console.error(err.stack ? err.stack : err); }
process.exit(1);
}
// everything ok, set up Promise-based methods // everything ok, set up Promise-based methods
['get', 'set', 'findKeys', 'getSub', 'setSub', 'remove', 'doShutdown'].forEach((fn) => { ['get', 'set', 'findKeys', 'getSub', 'setSub', 'remove', 'doShutdown'].forEach((fn) => {
exports[fn] = util.promisify(db[fn].bind(db)); exports[fn] = util.promisify(db[fn].bind(db));
});
// set up wrappers for get and getSub that can't return "undefined"
const get = exports.get;
exports.get = async function (key) {
const result = await get(key);
return (result === undefined) ? null : result;
};
const getSub = exports.getSub;
exports.getSub = async function (key, sub) {
const result = await getSub(key, sub);
return (result === undefined) ? null : result;
};
// exposed for those callers that need the underlying raw API
exports.db = db;
resolve();
}); });
// set up wrappers for get and getSub that can't return "undefined"
const get = exports.get;
exports.get = async (key) => {
const result = await get(key);
return (result === undefined) ? null : result;
};
const getSub = exports.getSub;
exports.getSub = async (key, sub) => {
const result = await getSub(key, sub);
return (result === undefined) ? null : result;
};
// exposed for those callers that need the underlying raw API
exports.db = db;
resolve();
}); });
}; });
exports.shutdown = async (hookName, context) => { exports.shutdown = async (hookName, context) => {
await exports.doShutdown(); await exports.doShutdown();

View file

@ -1,3 +1,5 @@
'use strict';
const _ = require('underscore'); const _ = require('underscore');
const cookieParser = require('cookie-parser'); const cookieParser = require('cookie-parser');
const express = require('express'); const express = require('express');
@ -5,9 +7,7 @@ const expressSession = require('express-session');
const fs = require('fs'); const fs = require('fs');
const hooks = require('../../static/js/pluginfw/hooks'); const hooks = require('../../static/js/pluginfw/hooks');
const log4js = require('log4js'); const log4js = require('log4js');
const npm = require('npm/lib/npm'); const SessionStore = require('../db/SessionStore');
const path = require('path');
const sessionStore = require('../db/SessionStore');
const settings = require('../utils/Settings'); const settings = require('../utils/Settings');
const stats = require('../stats'); const stats = require('../stats');
const util = require('util'); const util = require('util');
@ -36,13 +36,16 @@ exports.createServer = async () => {
if (!_.isEmpty(settings.users)) { if (!_.isEmpty(settings.users)) {
console.log(`The plugin admin page is at http://${settings.ip}:${settings.port}/admin/plugins`); console.log(`The plugin admin page is at http://${settings.ip}:${settings.port}/admin/plugins`);
} else { } else {
console.warn("Admin username and password not set in settings.json. To access admin please uncomment and edit 'users' in settings.json"); console.warn('Admin username and password not set in settings.json. ' +
'To access admin please uncomment and edit "users" in settings.json');
} }
const env = process.env.NODE_ENV || 'development'; const env = process.env.NODE_ENV || 'development';
if (env !== 'production') { if (env !== 'production') {
console.warn('Etherpad is running in Development mode. This mode is slower for users and less secure than production mode. You should set the NODE_ENV environment variable to production by using: export NODE_ENV=production'); console.warn('Etherpad is running in Development mode. This mode is slower for users and ' +
'less secure than production mode. You should set the NODE_ENV environment ' +
'variable to production by using: export NODE_ENV=production');
} }
}; };
@ -138,7 +141,7 @@ exports.restartServer = async () => {
exports.sessionMiddleware = expressSession({ exports.sessionMiddleware = expressSession({
secret: settings.sessionKey, secret: settings.sessionKey,
store: new sessionStore(), store: new SessionStore(),
resave: false, resave: false,
saveUninitialized: true, saveUninitialized: true,
// Set the cookie name to a javascript identifier compatible string. Makes code handling it // Set the cookie name to a javascript identifier compatible string. Makes code handling it

View file

@ -1,9 +1,11 @@
const eejs = require('ep_etherpad-lite/node/eejs'); 'use strict';
const settings = require('ep_etherpad-lite/node/utils/Settings');
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
const fs = require('fs');
exports.expressCreateServer = function (hook_name, args, cb) { const eejs = require('../../eejs');
const fs = require('fs');
const hooks = require('../../../static/js/pluginfw/hooks');
const settings = require('../../utils/Settings');
exports.expressCreateServer = (hookName, args, cb) => {
args.app.get('/admin/settings', (req, res) => { args.app.get('/admin/settings', (req, res) => {
res.send(eejs.require('ep_etherpad-lite/templates/admin/settings.html', { res.send(eejs.require('ep_etherpad-lite/templates/admin/settings.html', {
req, req,
@ -14,10 +16,11 @@ exports.expressCreateServer = function (hook_name, args, cb) {
return cb(); return cb();
}; };
exports.socketio = function (hook_name, args, cb) { exports.socketio = (hookName, args, cb) => {
const io = args.io.of('/settings'); const io = args.io.of('/settings');
io.on('connection', (socket) => { io.on('connection', (socket) => {
if (!socket.conn.request.session || !socket.conn.request.session.user || !socket.conn.request.session.user.is_admin) return; const {session: {user: {is_admin: isAdmin} = {}} = {}} = socket.conn.request;
if (!isAdmin) return;
socket.on('load', (query) => { socket.on('load', (query) => {
fs.readFile('settings.json', 'utf8', (err, data) => { fs.readFile('settings.json', 'utf8', (err, data) => {

View file

@ -1,13 +1,15 @@
'use strict';
const express = require('../express'); const express = require('../express');
const proxyaddr = require('proxy-addr'); const proxyaddr = require('proxy-addr');
const settings = require('../../utils/Settings'); const settings = require('../../utils/Settings');
const socketio = require('socket.io'); const socketio = require('socket.io');
const socketIORouter = require('../../handler/SocketIORouter'); const socketIORouter = require('../../handler/SocketIORouter');
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); const hooks = require('../../../static/js/pluginfw/hooks');
const padMessageHandler = require('../../handler/PadMessageHandler'); const padMessageHandler = require('../../handler/PadMessageHandler');
exports.expressCreateServer = function (hook_name, args, cb) { exports.expressCreateServer = (hookName, args, cb) => {
// init socket.io and redirect all requests to the MessageHandler // init socket.io and redirect all requests to the MessageHandler
// there shouldn't be a browser that isn't compatible to all // there shouldn't be a browser that isn't compatible to all
// transports in this list at once // transports in this list at once

View file

@ -1,4 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict';
/** /**
* This module is started with bin/run.sh. It sets up a Express HTTP and a Socket.IO Server. * This module is started with bin/run.sh. It sets up a Express HTTP and a Socket.IO Server.
* Static file Requests are answered directly from this module, Socket.IO messages are passed * Static file Requests are answered directly from this module, Socket.IO messages are passed
@ -35,9 +38,9 @@ NodeVersion.checkDeprecationStatus('10.13.0', '1.8.3');
const UpdateCheck = require('./utils/UpdateCheck'); const UpdateCheck = require('./utils/UpdateCheck');
const db = require('./db/DB'); const db = require('./db/DB');
const express = require('./hooks/express'); const express = require('./hooks/express');
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); const hooks = require('../static/js/pluginfw/hooks');
const npm = require('npm/lib/npm.js'); const npm = require('npm/lib/npm.js');
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins'); const plugins = require('../static/js/pluginfw/plugins');
const settings = require('./utils/Settings'); const settings = require('./utils/Settings');
const util = require('util'); const util = require('util');

View file

@ -1,3 +1,5 @@
'use strict';
const measured = require('measured-core'); const measured = require('measured-core');
module.exports = measured.createCollection(); module.exports = measured.createCollection();

View file

@ -1,3 +1,5 @@
'use strict';
/** /**
* This Module manages all /minified/* requests. It controls the * This Module manages all /minified/* requests. It controls the
* minification && compression of Javascript and CSS. * minification && compression of Javascript and CSS.
@ -23,10 +25,8 @@ const ERR = require('async-stacktrace');
const settings = require('./Settings'); const settings = require('./Settings');
const async = require('async'); const async = require('async');
const fs = require('fs'); const fs = require('fs');
const StringDecoder = require('string_decoder').StringDecoder;
const CleanCSS = require('clean-css');
const path = require('path'); const path = require('path');
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs'); const plugins = require('../../static/js/pluginfw/plugin_defs');
const RequireKernel = require('etherpad-require-kernel'); const RequireKernel = require('etherpad-require-kernel');
const urlutil = require('url'); const urlutil = require('url');
const mime = require('mime-types'); const mime = require('mime-types');
@ -39,7 +39,7 @@ const ROOT_DIR = path.normalize(`${__dirname}/../../static/`);
const TAR_PATH = path.join(__dirname, 'tar.json'); const TAR_PATH = path.join(__dirname, 'tar.json');
const tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8')); const tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));
const threadsPool = Threads.Pool(() => Threads.spawn(new Threads.Worker('./MinifyWorker')), 2); const threadsPool = new Threads.Pool(() => Threads.spawn(new Threads.Worker('./MinifyWorker')), 2);
const LIBRARY_WHITELIST = [ const LIBRARY_WHITELIST = [
'async', 'async',
@ -53,30 +53,28 @@ const LIBRARY_WHITELIST = [
// Rewrite tar to include modules with no extensions and proper rooted paths. // Rewrite tar to include modules with no extensions and proper rooted paths.
const LIBRARY_PREFIX = 'ep_etherpad-lite/static/js'; const LIBRARY_PREFIX = 'ep_etherpad-lite/static/js';
exports.tar = {}; exports.tar = {};
function prefixLocalLibraryPath(path) { const prefixLocalLibraryPath = (path) => {
if (path.charAt(0) == '$') { if (path.charAt(0) === '$') {
return path.slice(1); return path.slice(1);
} else { } else {
return `${LIBRARY_PREFIX}/${path}`; return `${LIBRARY_PREFIX}/${path}`;
} }
} };
for (const [key, relativeFiles] of Object.entries(tar)) {
for (const key in tar) { const files = relativeFiles.map(prefixLocalLibraryPath);
exports.tar[prefixLocalLibraryPath(key)] = exports.tar[prefixLocalLibraryPath(key)] = files
tar[key].map(prefixLocalLibraryPath).concat( .concat(files.map((p) => p.replace(/\.js$/, '')))
tar[key].map(prefixLocalLibraryPath).map((p) => p.replace(/\.js$/, '')) .concat(files.map((p) => `${p.replace(/\.js$/, '')}/index.js`));
).concat(
tar[key].map(prefixLocalLibraryPath).map((p) => `${p.replace(/\.js$/, '')}/index.js`)
);
} }
// What follows is a terrible hack to avoid loop-back within the server. // What follows is a terrible hack to avoid loop-back within the server.
// TODO: Serve files from another service, or directly from the file system. // TODO: Serve files from another service, or directly from the file system.
function requestURI(url, method, headers, callback) { const requestURI = (url, method, headers, callback) => {
const parsedURL = urlutil.parse(url); const parsedURL = urlutil.parse(url);
let status = 500; var headers = {}; const let status = 500;
content = []; var headers = {};
const content = [];
const mockRequest = { const mockRequest = {
url, url,
@ -85,7 +83,7 @@ function requestURI(url, method, headers, callback) {
headers, headers,
}; };
const mockResponse = { const mockResponse = {
writeHead(_status, _headers) { writeHead: (_status, _headers) => {
status = _status; status = _status;
for (const header in _headers) { for (const header in _headers) {
if (Object.prototype.hasOwnProperty.call(_headers, header)) { if (Object.prototype.hasOwnProperty.call(_headers, header)) {
@ -93,61 +91,60 @@ function requestURI(url, method, headers, callback) {
} }
} }
}, },
setHeader(header, value) { setHeader: (header, value) => {
headers[header.toLowerCase()] = value.toString(); headers[header.toLowerCase()] = value.toString();
}, },
header(header, value) { header: (header, value) => {
headers[header.toLowerCase()] = value.toString(); headers[header.toLowerCase()] = value.toString();
}, },
write(_content) { write: (_content) => {
_content && content.push(_content); _content && content.push(_content);
}, },
end(_content) { end: (_content) => {
_content && content.push(_content); _content && content.push(_content);
callback(status, headers, content.join('')); callback(status, headers, content.join(''));
}, },
}; };
minify(mockRequest, mockResponse); minify(mockRequest, mockResponse);
} };
function requestURIs(locations, method, headers, callback) {
const requestURIs = (locations, method, headers, callback) => {
let pendingRequests = locations.length; let pendingRequests = locations.length;
const responses = []; const responses = [];
function respondFor(i) { const completed = () => {
return function (status, headers, content) {
responses[i] = [status, headers, content];
if (--pendingRequests == 0) {
completed();
}
};
}
for (let i = 0, ii = locations.length; i < ii; i++) {
requestURI(locations[i], method, headers, respondFor(i));
}
function completed() {
const statuss = responses.map((x) => x[0]); const statuss = responses.map((x) => x[0]);
const headerss = responses.map((x) => x[1]); const headerss = responses.map((x) => x[1]);
const contentss = responses.map((x) => x[2]); const contentss = responses.map((x) => x[2]);
callback(statuss, headerss, contentss); callback(statuss, headerss, contentss);
};
const respondFor = (i) => (status, headers, content) => {
responses[i] = [status, headers, content];
if (--pendingRequests === 0) {
completed();
}
};
for (let i = 0, ii = locations.length; i < ii; i++) {
requestURI(locations[i], method, headers, respondFor(i));
} }
} };
/** /**
* creates the minifed javascript for the given minified name * creates the minifed javascript for the given minified name
* @param req the Express request * @param req the Express request
* @param res the Express response * @param res the Express response
*/ */
function minify(req, res) { const minify = (req, res) => {
let filename = req.params.filename; let filename = req.params.filename;
// No relative paths, especially if they may go up the file hierarchy. // No relative paths, especially if they may go up the file hierarchy.
filename = path.normalize(path.join(ROOT_DIR, filename)); filename = path.normalize(path.join(ROOT_DIR, filename));
filename = filename.replace(/\.\./g, ''); filename = filename.replace(/\.\./g, '');
if (filename.indexOf(ROOT_DIR) == 0) { if (filename.indexOf(ROOT_DIR) === 0) {
filename = filename.slice(ROOT_DIR.length); filename = filename.slice(ROOT_DIR.length);
filename = filename.replace(/\\/g, '/'); filename = filename.replace(/\\/g, '/');
} else { } else {
@ -161,7 +158,7 @@ function minify(req, res) {
are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js, are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js,
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
*/ */
const match = filename.match(/^plugins\/([^\/]+)(\/(?:(static\/.*)|.*))?$/); const match = filename.match(/^plugins\/([^/]+)(\/(?:(static\/.*)|.*))?$/);
if (match) { if (match) {
const library = match[1]; const library = match[1];
const libraryPath = match[2] || ''; const libraryPath = match[2] || '';
@ -171,7 +168,7 @@ function minify(req, res) {
const pluginPath = plugin.package.realPath; const pluginPath = plugin.package.realPath;
filename = path.relative(ROOT_DIR, pluginPath + libraryPath); filename = path.relative(ROOT_DIR, pluginPath + libraryPath);
filename = filename.replace(/\\/g, '/'); // windows path fix filename = filename.replace(/\\/g, '/'); // windows path fix
} else if (LIBRARY_WHITELIST.indexOf(library) != -1) { } else if (LIBRARY_WHITELIST.indexOf(library) !== -1) {
// Go straight into node_modules // Go straight into node_modules
// Avoid `require.resolve()`, since 'mustache' and 'mustache/index.js' // Avoid `require.resolve()`, since 'mustache' and 'mustache/index.js'
// would end up resolving to logically distinct resources. // would end up resolving to logically distinct resources.
@ -203,11 +200,11 @@ function minify(req, res) {
} else if (new Date(req.headers['if-modified-since']) >= date) { } else if (new Date(req.headers['if-modified-since']) >= date) {
res.writeHead(304, {}); res.writeHead(304, {});
res.end(); res.end();
} else if (req.method == 'HEAD') { } else if (req.method === 'HEAD') {
res.header('Content-Type', contentType); res.header('Content-Type', contentType);
res.writeHead(200, {}); res.writeHead(200, {});
res.end(); res.end();
} else if (req.method == 'GET') { } else if (req.method === 'GET') {
getFileCompressed(filename, contentType, (error, content) => { getFileCompressed(filename, contentType, (error, content) => {
if (ERR(error, () => { if (ERR(error, () => {
res.writeHead(500, {}); res.writeHead(500, {});
@ -223,10 +220,10 @@ function minify(req, res) {
res.end(); res.end();
} }
}, 3); }, 3);
} };
// find all includes in ace.js and embed them. // find all includes in ace.js and embed them.
function getAceFile(callback) { const getAceFile = (callback) => {
fs.readFile(`${ROOT_DIR}js/ace.js`, 'utf8', (err, data) => { fs.readFile(`${ROOT_DIR}js/ace.js`, 'utf8', (err, data) => {
if (ERR(err, callback)) return; if (ERR(err, callback)) return;
@ -256,10 +253,10 @@ function getAceFile(callback) {
resourceURI = resourceURI.replace(/\\/g, '/'); // Windows (safe generally?) resourceURI = resourceURI.replace(/\\/g, '/'); // Windows (safe generally?)
requestURI(resourceURI, 'GET', {}, (status, headers, body) => { requestURI(resourceURI, 'GET', {}, (status, headers, body) => {
const error = !(status == 200 || status == 404); const error = !(status === 200 || status === 404);
if (!error) { if (!error) {
data += `Ace2Editor.EMBEDED[${JSON.stringify(filename)}] = ${ data += `Ace2Editor.EMBEDED[${JSON.stringify(filename)}] = ${
JSON.stringify(status == 200 ? body || '' : null)};\n`; JSON.stringify(status === 200 ? body || '' : null)};\n`;
} else { } else {
console.error(`getAceFile(): error getting ${resourceURI}. Status code: ${status}`); console.error(`getAceFile(): error getting ${resourceURI}. Status code: ${status}`);
} }
@ -269,10 +266,10 @@ function getAceFile(callback) {
callback(error, data); callback(error, data);
}); });
}); });
} };
// Check for the existance of the file and get the last modification date. // Check for the existance of the file and get the last modification date.
function statFile(filename, callback, dirStatLimit) { const statFile = (filename, callback, dirStatLimit) => {
/* /*
* The only external call to this function provides an explicit value for * The only external call to this function provides an explicit value for
* dirStatLimit: this check could be removed. * dirStatLimit: this check could be removed.
@ -281,20 +278,20 @@ function statFile(filename, callback, dirStatLimit) {
dirStatLimit = 3; dirStatLimit = 3;
} }
if (dirStatLimit < 1 || filename == '' || filename == '/') { if (dirStatLimit < 1 || filename === '' || filename === '/') {
callback(null, null, false); callback(null, null, false);
} else if (filename == 'js/ace.js') { } else if (filename === 'js/ace.js') {
// Sometimes static assets are inlined into this file, so we have to stat // Sometimes static assets are inlined into this file, so we have to stat
// everything. // everything.
lastModifiedDateOfEverything((error, date) => { lastModifiedDateOfEverything((error, date) => {
callback(error, date, !error); callback(error, date, !error);
}); });
} else if (filename == 'js/require-kernel.js') { } else if (filename === 'js/require-kernel.js') {
callback(null, requireLastModified(), true); callback(null, requireLastModified(), true);
} else { } else {
fs.stat(ROOT_DIR + filename, (error, stats) => { fs.stat(ROOT_DIR + filename, (error, stats) => {
if (error) { if (error) {
if (error.code == 'ENOENT') { if (error.code === 'ENOENT') {
// Stat the directory instead. // Stat the directory instead.
statFile(path.dirname(filename), (error, date, exists) => { statFile(path.dirname(filename), (error, date, exists) => {
callback(error, date, false); callback(error, date, false);
@ -309,8 +306,9 @@ function statFile(filename, callback, dirStatLimit) {
} }
}); });
} }
} };
function lastModifiedDateOfEverything(callback) {
const lastModifiedDateOfEverything = (callback) => {
const folders2check = [`${ROOT_DIR}js/`, `${ROOT_DIR}css/`]; const folders2check = [`${ROOT_DIR}js/`, `${ROOT_DIR}css/`];
let latestModification = 0; let latestModification = 0;
// go trough this two folders // go trough this two folders
@ -343,23 +341,19 @@ function lastModifiedDateOfEverything(callback) {
}, () => { }, () => {
callback(null, latestModification); callback(null, latestModification);
}); });
} };
// This should be provided by the module, but until then, just use startup // This should be provided by the module, but until then, just use startup
// time. // time.
const _requireLastModified = new Date(); const _requireLastModified = new Date();
function requireLastModified() { const requireLastModified = () => _requireLastModified.toUTCString();
return _requireLastModified.toUTCString(); const requireDefinition = () => `var require = ${RequireKernel.kernelSource};\n`;
}
function requireDefinition() {
return `var require = ${RequireKernel.kernelSource};\n`;
}
function getFileCompressed(filename, contentType, callback) { const getFileCompressed = (filename, contentType, callback) => {
getFile(filename, (error, content) => { getFile(filename, (error, content) => {
if (error || !content || !settings.minify) { if (error || !content || !settings.minify) {
callback(error, content); callback(error, content);
} else if (contentType == 'application/javascript') { } else if (contentType === 'application/javascript') {
threadsPool.queue(async ({compressJS}) => { threadsPool.queue(async ({compressJS}) => {
try { try {
logger.info('Compress JS file %s.', filename); logger.info('Compress JS file %s.', filename);
@ -373,12 +367,13 @@ function getFileCompressed(filename, contentType, callback) {
content = compressResult.code.toString(); // Convert content obj code to string content = compressResult.code.toString(); // Convert content obj code to string
} }
} catch (error) { } catch (error) {
console.error(`getFile() returned an error in getFileCompressed(${filename}, ${contentType}): ${error}`); console.error('getFile() returned an error in ' +
`getFileCompressed(${filename}, ${contentType}): ${error}`);
} }
callback(null, content); callback(null, content);
}); });
} else if (contentType == 'text/css') { } else if (contentType === 'text/css') {
threadsPool.queue(async ({compressCSS}) => { threadsPool.queue(async ({compressCSS}) => {
try { try {
logger.info('Compress CSS file %s.', filename); logger.info('Compress CSS file %s.', filename);
@ -394,17 +389,17 @@ function getFileCompressed(filename, contentType, callback) {
callback(null, content); callback(null, content);
} }
}); });
} };
function getFile(filename, callback) { const getFile = (filename, callback) => {
if (filename == 'js/ace.js') { if (filename === 'js/ace.js') {
getAceFile(callback); getAceFile(callback);
} else if (filename == 'js/require-kernel.js') { } else if (filename === 'js/require-kernel.js') {
callback(undefined, requireDefinition()); callback(undefined, requireDefinition());
} else { } else {
fs.readFile(ROOT_DIR + filename, callback); fs.readFile(ROOT_DIR + filename, callback);
} }
} };
exports.minify = minify; exports.minify = minify;

View file

@ -1,7 +1,8 @@
'use strict';
$(document).ready(() => { $(document).ready(() => {
let socket;
const loc = document.location; const loc = document.location;
const port = loc.port == '' ? (loc.protocol == 'https:' ? 443 : 80) : loc.port; const port = loc.port === '' ? (loc.protocol === 'https:' ? 443 : 80) : loc.port;
const url = `${loc.protocol}//${loc.hostname}:${port}/`; const url = `${loc.protocol}//${loc.hostname}:${port}/`;
const pathComponents = location.pathname.split('/'); const pathComponents = location.pathname.split('/');
// Strip admin/plugins // Strip admin/plugins
@ -10,7 +11,7 @@ $(document).ready(() => {
// connect // connect
const room = `${url}settings`; const room = `${url}settings`;
socket = io.connect(room, {path: `${baseURL}socket.io`, resource}); const socket = io.connect(room, {path: `${baseURL}socket.io`, resource});
socket.on('settings', (settings) => { socket.on('settings', (settings) => {
/* Check whether the settings.json is authorized to be viewed */ /* Check whether the settings.json is authorized to be viewed */
@ -58,18 +59,13 @@ $(document).ready(() => {
}); });
function isJSONClean(data) { const isJSONClean = (data) => {
let cleanSettings = JSON.minify(data); let cleanSettings = JSON.minify(data);
// this is a bit naive. In theory some key/value might contain the sequences ',]' or ',}' // this is a bit naive. In theory some key/value might contain the sequences ',]' or ',}'
cleanSettings = cleanSettings.replace(',]', ']').replace(',}', '}'); cleanSettings = cleanSettings.replace(',]', ']').replace(',}', '}');
try { try {
var response = jQuery.parseJSON(cleanSettings); return typeof jQuery.parseJSON(cleanSettings) === 'object';
} catch (e) { } catch (e) {
return false; // the JSON failed to be parsed return false; // the JSON failed to be parsed
} }
if (typeof response !== 'object') { };
return false;
} else {
return true;
}
}

View file

@ -1,14 +1,12 @@
/* global __dirname, exports, require */ 'use strict';
function m(mod) { return `${__dirname}/../../src/${mod}`; } const apiHandler = require('ep_etherpad-lite/node/handler/APIHandler');
const log4js = require('ep_etherpad-lite/node_modules/log4js');
const apiHandler = require(m('node/handler/APIHandler'));
const log4js = require(m('node_modules/log4js'));
const process = require('process'); const process = require('process');
const server = require(m('node/server')); const server = require('ep_etherpad-lite/node/server');
const settings = require(m('node/utils/Settings')); const settings = require('ep_etherpad-lite/node/utils/Settings');
const supertest = require(m('node_modules/supertest')); const supertest = require('ep_etherpad-lite/node_modules/supertest');
const webaccess = require(m('node/hooks/express/webaccess')); const webaccess = require('ep_etherpad-lite/node/hooks/express/webaccess');
const backups = {}; const backups = {};
let inited = false; let inited = false;

View file

@ -1,14 +1,12 @@
/* global __dirname, __filename, afterEach, before, beforeEach, clearTimeout, describe, it, require, setTimeout */ 'use strict';
function m(mod) { return `${__dirname}/../../../src/${mod}`; }
const assert = require('assert').strict; const assert = require('assert').strict;
const common = require('../common'); const common = require('../common');
const io = require(m('node_modules/socket.io-client')); const io = require('ep_etherpad-lite/node_modules/socket.io-client');
const padManager = require(m('node/db/PadManager')); const padManager = require('ep_etherpad-lite/node/db/PadManager');
const plugins = require(m('static/js/pluginfw/plugin_defs')); const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
const setCookieParser = require(m('node_modules/set-cookie-parser')); const setCookieParser = require('ep_etherpad-lite/node_modules/set-cookie-parser');
const settings = require(m('node/utils/Settings')); const settings = require('ep_etherpad-lite/node/utils/Settings');
const logger = common.logger; const logger = common.logger;
@ -50,7 +48,8 @@ const getSocketEvent = async (socket, event) => {
const connect = async (res) => { const connect = async (res) => {
// Convert the `set-cookie` header(s) into a `cookie` header. // Convert the `set-cookie` header(s) into a `cookie` header.
const resCookies = (res == null) ? {} : setCookieParser.parse(res, {map: true}); const resCookies = (res == null) ? {} : setCookieParser.parse(res, {map: true});
const reqCookieHdr = Object.entries(resCookies).map(([name, cookie]) => `${name}=${encodeURIComponent(cookie.value)}`).join('; '); const reqCookieHdr = Object.entries(resCookies).map(
([name, cookie]) => `${name}=${encodeURIComponent(cookie.value)}`).join('; ');
logger.debug('socket.io connecting...'); logger.debug('socket.io connecting...');
const socket = io(`${common.baseUrl}/`, { const socket = io(`${common.baseUrl}/`, {