Migrated settings to es6

This commit is contained in:
SamTV12345 2024-08-17 10:23:03 +02:00
parent 6ed711a4d8
commit 154e67315c
39 changed files with 710 additions and 702 deletions

View file

@ -297,6 +297,9 @@ importers:
'@types/jsdom':
specifier: ^21.1.7
version: 21.1.7
'@types/jsonminify':
specifier: ^0.4.3
version: 0.4.3
'@types/jsonwebtoken':
specifier: ^9.0.6
version: 9.0.6
@ -1516,6 +1519,9 @@ packages:
'@types/json5@0.0.29':
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
'@types/jsonminify@0.4.3':
resolution: {integrity: sha512-+oz7EbPz1Nwmn/sr3UztgXpRhdFpvFrjGi5ictEYxUri5ZvQMTcdTi36MTfD/gCb1A5xhJKdH8Hwz2uz5k6s9A==}
'@types/jsonwebtoken@9.0.6':
resolution: {integrity: sha512-/5hndP5dCjloafCXns6SZyESp3Ldq7YjH3zwzwczYnjxIT0Fqzk5ROSYVGfFyczIue7IUEj8hkvLbPoLQ18vQw==}
@ -5703,6 +5709,8 @@ snapshots:
'@types/json5@0.0.29': {}
'@types/jsonminify@0.4.3': {}
'@types/jsonwebtoken@9.0.6':
dependencies:
'@types/node': 22.4.0

View file

@ -22,7 +22,7 @@
*/
import {Database} from 'ueberdb2';
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
import log4js from 'log4js';
const stats = require('../stats')

View file

@ -14,7 +14,7 @@ import AttributePool from '../../static/js/AttributePool';
const Stream = require('../utils/Stream');
const assert = require('assert').strict;
const db = require('./DB');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
const authorManager = require('./AuthorManager');
const padManager = require('./PadManager');
const padMessageHandler = require('../handler/PadMessageHandler');

View file

@ -25,7 +25,7 @@ import {PadType} from "../types/PadType";
const CustomError = require('../utils/customError');
const Pad = require('../db/Pad');
const db = require('./DB');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
/**
* A cache of all loaded Pads.

View file

@ -26,7 +26,7 @@ const hooks = require('../../static/js/pluginfw/hooks');
const padManager = require('./PadManager');
const readOnlyManager = require('./ReadOnlyManager');
const sessionManager = require('./SessionManager');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
const webaccess = require('../hooks/express/webaccess');
const log4js = require('log4js');
const authLogger = log4js.getLogger('auth');

View file

@ -25,7 +25,7 @@ const fs = require('fs');
const hooks = require('../../static/js/pluginfw/hooks');
const path = require('path');
const resolve = require('resolve');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
import {pluginInstallPath} from '../../static/js/pluginfw/installer'
const templateCache = new Map();

View file

@ -1,15 +1,15 @@
const absolutePaths = require('../utils/AbsolutePaths');
import fs from 'fs';
import log4js from 'log4js';
const randomString = require('../utils/randomstring');
const argv = require('../utils/Cli').argv;
const settings = require('../utils/Settings');
import randomString from '../utils/randomstring';
import {argvP} from '../utils/Cli'
import settings from '../utils/Settings';
const apiHandlerLogger = log4js.getLogger('APIHandler');
// ensure we have an apikey
export let apikey:string|null = null;
const apikeyFilename = absolutePaths.makeAbsolute(argv.apikey || './APIKEY.txt');
const apikeyFilename = absolutePaths.makeAbsolute(argvP.apikey || './APIKEY.txt');
if(settings.authenticationMethod === 'apikey') {

View file

@ -25,7 +25,7 @@ const padManager = require('../db/PadManager');
const padMessageHandler = require('./PadMessageHandler');
import {promises as fs} from 'fs';
import path from 'path';
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
const {Formidable} = require('formidable');
import os from 'os';
const importHtml = require('../utils/ImportHtml');

View file

@ -30,7 +30,7 @@ const AttributeManager = require('../../static/js/AttributeManager');
const authorManager = require('../db/AuthorManager');
import padutils from '../../static/js/pad_utils';
const readOnlyManager = require('../db/ReadOnlyManager');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
const securityManager = require('../db/SecurityManager');
const plugins = require('../../static/js/pluginfw/plugin_defs');
import log4js from 'log4js';

View file

@ -23,7 +23,7 @@
import {MapArrayType} from "../types/MapType";
import {SocketModule} from "../types/SocketModule";
const log4js = require('log4js');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
const stats = require('../../node/stats')
const logger = log4js.getLogger('socket.io');

View file

@ -14,7 +14,7 @@ import fs from 'fs';
const hooks = require('../../static/js/pluginfw/hooks');
import log4js from 'log4js';
const SessionStore = require('../db/SessionStore');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
const stats = require('../stats')
import util from 'util';
const webaccess = require('./express/webaccess');
@ -190,6 +190,7 @@ exports.restartServer = async () => {
secretRotator = new SecretRotator(
'expressSessionSecrets', keyRotationInterval, sessionLifetime, settings.sessionKey);
await secretRotator.start();
// @ts-ignore
secret = secretRotator.secrets;
}
if (!secret) throw new Error('missing cookie signing secret');

View file

@ -5,7 +5,7 @@ import fs from "fs";
import * as url from "node:url";
import {MapArrayType} from "../../types/MapType";
const settings = require('ep_etherpad-lite/node/utils/Settings');
import settings from 'ep_etherpad-lite/node/utils/Settings';
const ADMIN_PATH = path.join(settings.root, 'src', 'templates');
const PROXY_HEADER = "x-proxy-path"

View file

@ -9,7 +9,7 @@ const eejs = require('../../eejs');
const fsp = require('fs').promises;
const hooks = require('../../../static/js/pluginfw/hooks');
const plugins = require('../../../static/js/pluginfw/plugins');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
const UpdateCheck = require('../../utils/UpdateCheck');
const padManager = require('../../db/PadManager');
const api = require('../../db/API');

View file

@ -3,7 +3,7 @@
import {ArgsExpressType} from "../../types/ArgsExpressType";
const hasPadAccess = require('../../padaccess');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
const exportHandler = require('../../handler/ExportHandler');
const importHandler = require('../../handler/ImportHandler');
const padManager = require('../../db/PadManager');

View file

@ -24,7 +24,7 @@ const cloneDeep = require('lodash.clonedeep');
const createHTTPError = require('http-errors');
const apiHandler = require('../../handler/APIHandler');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
const log4js = require('log4js');
const logger = log4js.getLogger('API');

View file

@ -6,7 +6,7 @@ import events from 'events';
const express = require('../express');
import log4js from 'log4js';
const proxyaddr = require('proxy-addr');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
import {Server, Socket} from 'socket.io'
const socketIORouter = require('../../handler/SocketIORouter');
const hooks = require('../../../static/js/pluginfw/hooks');

View file

@ -6,7 +6,7 @@ import fs from 'node:fs';
const fsp = fs.promises;
const toolbar = require('../../utils/toolbar');
const hooks = require('../../../static/js/pluginfw/hooks');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
import util from 'node:util';
const webaccess = require('./webaccess');
const plugins = require('../../../static/js/pluginfw/plugin_defs');
@ -40,7 +40,7 @@ exports.expressPreSession = async (hookName:string, {app}:any) => {
app.get('/robots.txt', (req:any, res:any) => {
let filePath =
path.join(settings.root, 'src', 'static', 'skins', settings.skinName, 'robots.txt');
path.join(settings.root, 'src', 'static', 'skins', settings.skinName!, 'robots.txt');
res.sendFile(filePath, (err:any) => {
// there is no custom robots.txt, send the default robots.txt which dissallows all
if (err) {
@ -64,7 +64,7 @@ exports.expressPreSession = async (hookName:string, {app}:any) => {
const fns = [
...(settings.favicon ? [path.resolve(settings.root, settings.favicon)] : []),
path.join(settings.root, 'src', 'static', 'skins', settings.skinName, 'favicon.ico'),
path.join(settings.root, 'src', 'static', 'skins', settings.skinName!, 'favicon.ico'),
path.join(settings.root, 'src', 'static', 'favicon.ico'),
];
for (const fn of fns) {
@ -174,6 +174,7 @@ const handleLiveReload = async (args: any, padString: string, timeSliderString:
req,
toolbar,
isReadOnly,
settings: settings,
entrypoint: '/watch/pad?hash=' + hash
})
res.send(content);
@ -203,6 +204,7 @@ const handleLiveReload = async (args: any, padString: string, timeSliderString:
req,
toolbar,
isReadOnly,
settings: settings,
entrypoint: '/watch/timeslider?hash=' + hash
})
res.send(content);

View file

@ -7,7 +7,7 @@ const fs = require('fs').promises;
import {minify} from '../../utils/Minify';
import path from 'node:path';
const plugins = require('../../../static/js/pluginfw/plugin_defs');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
// Rewrite tar to include modules with no extensions and proper rooted paths.
const getTar = async () => {

View file

@ -7,7 +7,7 @@ const path = require('path');
const fsp = require('fs').promises;
const plugins = require('../../../static/js/pluginfw/plugin_defs');
const sanitizePathname = require('../../utils/sanitizePathname');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
// Returns all *.js files under specDir (recursively) as relative paths to specDir, using '/'
// instead of path.sep to separate pathname components.

View file

@ -6,7 +6,7 @@ import {SocketClientRequest} from "../../types/SocketClientRequest";
import {WebAccessTypes} from "../../types/WebAccessTypes";
import {SettingsUser} from "../../types/SettingsUser";
const httpLogger = log4js.getLogger('http');
const settings = require('../../utils/Settings');
import settings from '../../utils/Settings';
const hooks = require('../../../static/js/pluginfw/hooks');
const readOnlyManager = require('../../db/ReadOnlyManager');

View file

@ -9,7 +9,7 @@ const path = require('path');
const _ = require('underscore');
const pluginDefs = require('../../static/js/pluginfw/plugin_defs');
const existsSync = require('../utils/path_exists');
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
// returns all existing messages merged together and grouped by langcode
// {es: {"foo": "string"}, en:...}

View file

@ -3,7 +3,7 @@ import Provider, {Account, Configuration} from 'oidc-provider';
import {generateKeyPair, exportJWK, KeyLike} from 'jose'
import MemoryAdapter from "./OIDCAdapter";
import path from "path";
const settings = require('../utils/Settings');
import settings from '../utils/Settings';
import {IncomingForm} from 'formidable'
import express, {Request, Response} from 'express';
import {format} from 'url'
@ -137,7 +137,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
} else if (token.kind === "ClientCredentials") {
let extraParams: MapArrayType<string> = {}
settings.sso.clients
settings.sso.clients!
.filter((client:any) => client.client_id === token.clientId)
.forEach((client:any) => {
if(client.extraParams !== undefined) {

View file

@ -29,7 +29,7 @@ import pkg from '../package.json';
import {checkForMigration} from "../static/js/pluginfw/installer";
import axios from "axios";
const settings = require('./utils/Settings');
import settings from './utils/Settings';
let wtfnode: any;
if (settings.dumpOnUncleanExit) {

View file

@ -24,7 +24,7 @@ import {AsyncQueueTask} from "../types/AsyncQueueTask";
const spawn = require('child_process').spawn;
const async = require('async');
const settings = require('./Settings');
import settings from './Settings';
const os = require('os');
// on windows we have to spawn a process for each convertion,

View file

@ -18,9 +18,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const log4js = require('log4js');
const path = require('path');
const _ = require('underscore');
import log4js from 'log4js';
import path from 'path';
import _ from 'underscore';
const absPathLogger = log4js.getLogger('AbsolutePaths');
@ -43,8 +43,8 @@ let etherpadRoot: string|null = null;
const popIfEndsWith = (stringArray: string[], lastDesiredElements: string[]): string[] | false => {
if (stringArray.length <= lastDesiredElements.length) {
absPathLogger.debug(`In order to pop "${lastDesiredElements.join(path.sep)}" ` +
`from "${stringArray.join(path.sep)}", it should contain at least ` +
`${lastDesiredElements.length + 1} elements`);
`from "${stringArray.join(path.sep)}", it should contain at least ` +
`${lastDesiredElements.length + 1} elements`);
return false;
}
@ -55,7 +55,7 @@ const popIfEndsWith = (stringArray: string[], lastDesiredElements: string[]): st
}
absPathLogger.debug(
`${stringArray.join(path.sep)} does not end with "${lastDesiredElements.join(path.sep)}"`);
`${stringArray.join(path.sep)} does not end with "${lastDesiredElements.join(path.sep)}"`);
return false;
};
@ -74,7 +74,7 @@ const popIfEndsWith = (stringArray: string[], lastDesiredElements: string[]): st
* @return {string} The identified absolute base path. If such path cannot be
* identified, prints a log and exits the application.
*/
exports.findEtherpadRoot = () => {
export const findEtherpadRoot = () => {
if (etherpadRoot != null) {
return etherpadRoot;
}
@ -104,7 +104,7 @@ exports.findEtherpadRoot = () => {
if (maybeEtherpadRoot === false) {
absPathLogger.error('Could not identity Etherpad base path in this ' +
`${process.platform} installation in "${foundRoot}"`);
`${process.platform} installation in "${foundRoot}"`);
process.exit(1);
}
@ -116,7 +116,7 @@ exports.findEtherpadRoot = () => {
}
absPathLogger.error(
`To run, Etherpad has to identify an absolute base path. This is not: "${etherpadRoot}"`);
`To run, Etherpad has to identify an absolute base path. This is not: "${etherpadRoot}"`);
process.exit(1);
};
@ -130,12 +130,12 @@ exports.findEtherpadRoot = () => {
* it is returned unchanged. Otherwise it is interpreted
* relative to exports.root.
*/
exports.makeAbsolute = (somePath: string) => {
export const makeAbsolute = (somePath: string) => {
if (path.isAbsolute(somePath)) {
return somePath;
}
const rewrittenPath = path.join(exports.findEtherpadRoot(), somePath);
const rewrittenPath = path.join(findEtherpadRoot(), somePath);
absPathLogger.debug(`Relative path "${somePath}" can be rewritten to "${rewrittenPath}"`);
return rewrittenPath;
@ -149,7 +149,7 @@ exports.makeAbsolute = (somePath: string) => {
* a subdirectory of the base one
* @return {boolean}
*/
exports.isSubdir = (parent: string, arbitraryDir: string): boolean => {
export const isSubdir = (parent: string, arbitraryDir: string): boolean => {
// modified from: https://stackoverflow.com/questions/37521893/determine-if-a-path-is-subdirectory-of-another-in-node-js#45242825
const relative = path.relative(parent, arbitraryDir);
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);

View file

@ -21,7 +21,9 @@
*/
// An object containing the parsed command-line options
exports.argv = {};
import {MapArrayType} from "../types/MapType";
export const argvP: MapArrayType<any> = {};
const argv = process.argv.slice(2);
let arg, prevArg;
@ -32,22 +34,22 @@ for (let i = 0; i < argv.length; i++) {
// Override location of settings.json file
if (prevArg === '--settings' || prevArg === '-s') {
exports.argv.settings = arg;
argvP.settings = arg;
}
// Override location of credentials.json file
if (prevArg === '--credentials') {
exports.argv.credentials = arg;
argvP.credentials = arg;
}
// Override location of settings.json file
if (prevArg === '--sessionkey') {
exports.argv.sessionkey = arg;
argvP.sessionkey = arg;
}
// Override location of APIKEY.txt file
if (prevArg === '--apikey') {
exports.argv.apikey = arg;
argvP.apikey = arg;
}
prevArg = arg;

View file

@ -23,7 +23,7 @@ const log4js = require('log4js');
const os = require('os');
const path = require('path');
const runCmd = require('./run_cmd');
const settings = require('./Settings');
import settings from './Settings';
const logger = log4js.getLogger('LibreOffice');

View file

@ -26,7 +26,7 @@ import mime from 'mime-types';
import log4js from 'log4js';
import {compressCSS, compressJS} from './MinifyWorker'
const settings = require('./Settings');
import settings from './Settings';
import {promises as fs} from 'fs';
import path from 'node:path';
const plugins = require('../../static/js/pluginfw/plugin_defs');

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
'use strict';
const semver = require('semver');
const settings = require('./Settings');
import settings from './Settings';
import axios from 'axios';
const headers = {
'User-Agent': 'Etherpad/' + settings.getEpVersion(),

View file

@ -3,8 +3,8 @@
* Generates a random String with the given length. Is needed to generate the
* Author, Group, readonly, session Ids
*/
const cryptoMod = require('crypto');
import cryptoMod from 'crypto';
const randomString = (len: number) => cryptoMod.randomBytes(len).toString('hex');
module.exports = randomString;
export default randomString

View file

@ -8,7 +8,7 @@ import {Readable} from "node:stream";
const spawn = require('cross-spawn');
const log4js = require('log4js');
const path = require('path');
const settings = require('./Settings');
import settings from './Settings';
const logger = log4js.getLogger('runCmd');

View file

@ -88,6 +88,7 @@
"@types/jquery": "^3.5.30",
"@types/js-cookie": "^3.0.6",
"@types/jsdom": "^21.1.7",
"@types/jsonminify": "^0.4.3",
"@types/jsonwebtoken": "^9.0.6",
"@types/mime-types": "^2.1.4",
"@types/mocha": "^10.0.7",

View file

@ -4,7 +4,7 @@ import {node_modules, pluginInstallPath} from "./installer";
import {accessSync, constants, rmSync, symlinkSync, unlinkSync} from "node:fs";
import {dependencies, name} from '../../../package.json'
import {pathToFileURL} from 'node:url';
const settings = require('../../../node/utils/Settings');
import settings from '../../../node/utils/Settings';
import {readFileSync} from "fs";
export class LinkInstaller {

View file

@ -13,7 +13,7 @@ import {promises as fs} from "fs";
const plugins = require('./plugins');
const hooks = require('./hooks');
const runCmd = require('../../../node/utils/run_cmd');
const settings = require('../../../node/utils/Settings');
import settings from '../../../node/utils/Settings';
import {LinkInstaller} from "./LinkInstaller";
const {findEtherpadRoot} = require('../../../node/utils/AbsolutePaths');

View file

@ -9,7 +9,7 @@ const runCmd = require('../../../node/utils/run_cmd');
const tsort = require('./tsort');
const pluginUtils = require('./shared');
const defs = require('./plugin_defs');
const settings = require('../../../node/utils/Settings');
import settings from '../../../node/utils/Settings'
const logger = log4js.getLogger('plugins');

View file

@ -1,6 +1,5 @@
<%
var settings = require("ep_etherpad-lite/node/utils/Settings")
, langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs
var langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs
, pluginUtils = require('ep_etherpad-lite/static/js/pluginfw/shared')
;
%>

View file

@ -1,6 +1,5 @@
<%
var settings = require("ep_etherpad-lite/node/utils/Settings")
, langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs
var langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs
%>
<!doctype html>
<html translate="no" class="pad <%=settings.skinVariants%>">

View file

@ -10,7 +10,7 @@ import padutils from '../../static/js/pad_utils';
const process = require('process');
const server = require('../../node/server');
const setCookieParser = require('set-cookie-parser');
const settings = require('../../node/utils/Settings');
import settings from '../../node/utils/Settings';
import supertest from 'supertest';
import TestAgent from "supertest/lib/agent";
import {Http2Server} from "node:http2";
@ -26,7 +26,7 @@ export let baseUrl:string|null = null;
export let httpServer: Http2Server|null = null;
export const logger = log4js.getLogger('test');
const logLevel = logger.level;
const logLevel = logger.level as log4js.Level;
// Mocha doesn't monitor unhandled Promise rejections, so convert them to uncaught exceptions.
// https://github.com/mochajs/mocha/issues/2640