mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
Moved settings.js to ts.
This commit is contained in:
parent
71c74bc633
commit
fbf8667019
44 changed files with 852 additions and 760 deletions
|
@ -7,7 +7,7 @@ import {QueryType} from "../../types/QueryType";
|
|||
import {PluginType} from "../../types/Plugin";
|
||||
|
||||
const eejs = require('../../eejs');
|
||||
import * as settings from '../../utils/Settings';
|
||||
import {getEpVersion, getGitCommit} from '../../utils/Settings';
|
||||
const installer = require('../../../static/js/pluginfw/installer');
|
||||
const pluginDefs = require('../../../static/js/pluginfw/plugin_defs');
|
||||
const plugins = require('../../../static/js/pluginfw/plugins');
|
||||
|
@ -24,8 +24,8 @@ exports.expressCreateServer = (hookName:string, args: ArgsExpressType, cb:Functi
|
|||
});
|
||||
|
||||
args.app.get('/admin/plugins/info', (req:any, res:any) => {
|
||||
const gitCommit = settings.getGitCommit();
|
||||
const epVersion = settings.getEpVersion();
|
||||
const gitCommit = getGitCommit();
|
||||
const epVersion = getEpVersion();
|
||||
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/admin/plugins-info.html', {
|
||||
gitCommit,
|
||||
|
|
|
@ -4,8 +4,7 @@ const eejs = require('../../eejs');
|
|||
const fsp = require('fs').promises;
|
||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||
const plugins = require('../../../static/js/pluginfw/plugins');
|
||||
import {reloadSettings, settingsFilename, showSettingsInAdminPage} from '../../utils/Settings';
|
||||
import * as settings from '../../utils/Settings';
|
||||
import {reloadSettings, settings} from '../../utils/Settings';
|
||||
|
||||
exports.expressCreateServer = (hookName:string, {app}:any) => {
|
||||
app.get('/admin/settings', (req:any, res:any) => {
|
||||
|
@ -26,12 +25,12 @@ exports.socketio = (hookName:string, {io}:any) => {
|
|||
socket.on('load', async (query:string):Promise<any> => {
|
||||
let data;
|
||||
try {
|
||||
data = await fsp.readFile(settingsFilename, 'utf8');
|
||||
data = await fsp.readFile(settings.settingsFilename, 'utf8');
|
||||
} catch (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
// if showSettingsInAdminPage is set to false, then return NOT_ALLOWED in the result
|
||||
if (!showSettingsInAdminPage) {
|
||||
if (!settings.showSettingsInAdminPage) {
|
||||
socket.emit('settings', {results: 'NOT_ALLOWED'});
|
||||
} else {
|
||||
socket.emit('settings', {results: data});
|
||||
|
@ -39,7 +38,7 @@ exports.socketio = (hookName:string, {io}:any) => {
|
|||
});
|
||||
|
||||
socket.on('saveSettings', async (newSettings:string) => {
|
||||
await fsp.writeFile(settingsFilename, newSettings);
|
||||
await fsp.writeFile(settings.settingsFilename, newSettings);
|
||||
socket.emit('saveprogress', 'saved');
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const log4js = require('log4js');
|
||||
const clientLogger = log4js.getLogger('client');
|
||||
const {Formidable} = require('formidable');
|
||||
import {Formidable} from 'formidable';
|
||||
const apiHandler = require('../../handler/APIHandler');
|
||||
const util = require('util');
|
||||
|
||||
|
@ -25,6 +25,7 @@ exports.expressPreSession = async (hookName:string, {app}:any) => {
|
|||
// The Etherpad client side sends information about client side javscript errors
|
||||
app.post('/jserror', (req:any, res:any, next:Function) => {
|
||||
(async () => {
|
||||
// @ts-ignore
|
||||
const data = JSON.parse(await parseJserrorForm(req));
|
||||
clientLogger.warn(`${data.msg} --`, {
|
||||
[util.inspect.custom]: (depth: number, options:any) => {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import {ArgsExpressType} from "../../types/ArgsExpressType";
|
||||
|
||||
const hasPadAccess = require('../../padaccess');
|
||||
import {exportAvailable, importExportRateLimiting} from '../../utils/Settings';
|
||||
import {exportAvailable, settings} from '../../utils/Settings';
|
||||
const exportHandler = require('../../handler/ExportHandler');
|
||||
const importHandler = require('../../handler/ImportHandler');
|
||||
const padManager = require('../../db/PadManager');
|
||||
|
@ -14,7 +14,7 @@ const webaccess = require('./webaccess');
|
|||
|
||||
exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
||||
const limiter = rateLimit({
|
||||
...importExportRateLimiting,
|
||||
...settings.importExportRateLimiting,
|
||||
handler: (request:any) => {
|
||||
if (request.rateLimit.current === request.rateLimit.limit + 1) {
|
||||
// when the rate limiter triggers, write a warning in the logs
|
||||
|
|
|
@ -24,7 +24,7 @@ const cloneDeep = require('lodash.clonedeep');
|
|||
const createHTTPError = require('http-errors');
|
||||
|
||||
const apiHandler = require('../../handler/APIHandler');
|
||||
import {ssl} from '../../utils/Settings';
|
||||
import {settings} from '../../utils/Settings';
|
||||
|
||||
const log4js = require('log4js');
|
||||
const logger = log4js.getLogger('API');
|
||||
|
@ -724,5 +724,5 @@ const getApiRootForVersion = (version:string, style:any = APIPathStyle.FLAT): st
|
|||
const generateServerForApiVersion = (apiRoot:string, req:any): {
|
||||
url:string
|
||||
} => ({
|
||||
url: `${ssl ? 'https' : 'http'}://${req.headers.host}${apiRoot}`,
|
||||
url: `${settings.ssl ? 'https' : 'http'}://${req.headers.host}${apiRoot}`,
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@ const events = require('events');
|
|||
const express = require('../express');
|
||||
const log4js = require('log4js');
|
||||
const proxyaddr = require('proxy-addr');
|
||||
import * as settings from '../../utils/Settings';
|
||||
import {settings} from '../../utils/Settings';
|
||||
import {Server} from 'socket.io'
|
||||
const socketIORouter = require('../../handler/SocketIORouter');
|
||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||
|
|
|
@ -6,7 +6,7 @@ const fs = require('fs');
|
|||
const fsp = fs.promises;
|
||||
const toolbar = require('../../utils/toolbar');
|
||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||
import * as settings from '../../utils/Settings';
|
||||
import {getEpVersion, root, settings} from '../../utils/Settings';
|
||||
const util = require('util');
|
||||
const webaccess = require('./webaccess');
|
||||
|
||||
|
@ -17,7 +17,7 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
res.set('Content-Type', 'application/health+json');
|
||||
res.json({
|
||||
status: 'pass',
|
||||
releaseId: settings.getEpVersion(),
|
||||
releaseId: getEpVersion(),
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -31,11 +31,11 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
|
||||
app.get('/robots.txt', (req, res) => {
|
||||
let filePath =
|
||||
path.join(settings.root, 'src', 'static', 'skins', settings.skinName, 'robots.txt');
|
||||
path.join(root, 'src', 'static', 'skins', settings.skinName, 'robots.txt');
|
||||
res.sendFile(filePath, (err) => {
|
||||
// there is no custom robots.txt, send the default robots.txt which dissallows all
|
||||
if (err) {
|
||||
filePath = path.join(settings.root, 'src', 'static', 'robots.txt');
|
||||
filePath = path.join(root, 'src', 'static', 'robots.txt');
|
||||
res.sendFile(filePath);
|
||||
}
|
||||
});
|
||||
|
@ -54,9 +54,9 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
|
||||
|
||||
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', 'favicon.ico'),
|
||||
...(settings.favicon ? [path.resolve(root, settings.favicon)] : []),
|
||||
path.join(root, 'src', 'static', 'skins', settings.skinName, 'favicon.ico'),
|
||||
path.join(root, 'src', 'static', 'favicon.ico'),
|
||||
];
|
||||
for (const fn of fns) {
|
||||
try {
|
||||
|
|
|
@ -1,34 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const minify = require('../../utils/Minify');
|
||||
const path = require('path');
|
||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||
import * as settings from '../../utils/Settings';
|
||||
import {root, settings} from '../../utils/Settings';
|
||||
const CachingMiddleware = require('../../utils/caching_middleware');
|
||||
const Yajsml = require('etherpad-yajsml');
|
||||
|
||||
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
||||
const getTar = async () => {
|
||||
const prefixLocalLibraryPath = (path) => {
|
||||
const prefixLocalLibraryPath = (path: string) => {
|
||||
if (path.charAt(0) === '$') {
|
||||
return path.slice(1);
|
||||
} else {
|
||||
return `ep_etherpad-lite/static/js/${path}`;
|
||||
}
|
||||
};
|
||||
const tarJson = await fs.readFile(path.join(settings.root, 'src/node/utils/tar.json'), 'utf8');
|
||||
const tarJson = await fs.readFile(path.join(root, 'src/node/utils/tar.json'), 'utf8');
|
||||
const tar = {};
|
||||
for (const [key, relativeFiles] of Object.entries(JSON.parse(tarJson))) {
|
||||
// @ts-ignore
|
||||
const files = relativeFiles.map(prefixLocalLibraryPath);
|
||||
// @ts-ignore
|
||||
tar[prefixLocalLibraryPath(key)] = files
|
||||
.concat(files.map((p) => p.replace(/\.js$/, '')))
|
||||
.concat(files.map((p) => `${p.replace(/\.js$/, '')}/index.js`));
|
||||
.concat(files.map((p:string) => p.replace(/\.js$/, '')))
|
||||
.concat(files.map((p:string) => `${p.replace(/\.js$/, '')}/index.js`));
|
||||
}
|
||||
return tar;
|
||||
};
|
||||
|
||||
exports.expressPreSession = async (hookName, {app}) => {
|
||||
exports.expressPreSession = async (hookName: string, {app}:any) => {
|
||||
// Cache both minified and static.
|
||||
const assetCache = new CachingMiddleware();
|
||||
app.all(/\/javascripts\/(.*)/, assetCache.handle.bind(assetCache));
|
||||
|
@ -58,11 +61,13 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
// serve plugin definitions
|
||||
// not very static, but served here so that client can do
|
||||
// require("pluginfw/static/js/plugin-definitions.js");
|
||||
app.get('/pluginfw/plugin-definitions.json', (req, res, next) => {
|
||||
const clientParts = plugins.parts.filter((part) => part.client_hooks != null);
|
||||
app.get('/pluginfw/plugin-definitions.json', (req:any, res:any, next:Function) => {
|
||||
const clientParts = plugins.parts.filter((part:any) => part.client_hooks != null);
|
||||
const clientPlugins = {};
|
||||
for (const name of new Set(clientParts.map((part) => part.plugin))) {
|
||||
for (const name of new Set(clientParts.map((part:any) => part.plugin))) {
|
||||
// @ts-ignore
|
||||
clientPlugins[name] = {...plugins.plugins[name]};
|
||||
// @ts-ignore
|
||||
delete clientPlugins[name].package;
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
@ -4,7 +4,7 @@ const path = require('path');
|
|||
const fsp = require('fs').promises;
|
||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||
const sanitizePathname = require('../../utils/sanitizePathname');
|
||||
import * as settings from '../../utils/Settings';
|
||||
import {root, 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.
|
||||
|
@ -57,7 +57,7 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
})().catch((err) => next(err || new Error(err)));
|
||||
});
|
||||
|
||||
const rootTestFolder = path.join(settings.root, 'src/tests/frontend/');
|
||||
const rootTestFolder = path.join(root, 'src/tests/frontend/');
|
||||
|
||||
app.get('/tests/frontend/index.html', (req, res) => {
|
||||
res.redirect(['./', ...req.url.split('?').slice(1)].join('?'));
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const assert = require('assert').strict;
|
||||
const log4js = require('log4js');
|
||||
const httpLogger = log4js.getLogger('http');
|
||||
import * as settings from '../../utils/Settings';
|
||||
import {settings} from '../../utils/Settings';
|
||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||
const readOnlyManager = require('../../db/ReadOnlyManager');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue