mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
Moved more classes to ts. (#6179)
This commit is contained in:
parent
3ea6f1072d
commit
4bd27a1c79
22 changed files with 790 additions and 653 deletions
|
@ -10,10 +10,10 @@ const settings = require('../../utils/Settings');
|
|||
const util = require('util');
|
||||
const webaccess = require('./webaccess');
|
||||
|
||||
exports.expressPreSession = async (hookName, {app}) => {
|
||||
exports.expressPreSession = async (hookName:string, {app}:any) => {
|
||||
// This endpoint is intended to conform to:
|
||||
// https://www.ietf.org/archive/id/draft-inadarei-api-health-check-06.html
|
||||
app.get('/health', (req, res) => {
|
||||
app.get('/health', (req:any, res:any) => {
|
||||
res.set('Content-Type', 'application/health+json');
|
||||
res.json({
|
||||
status: 'pass',
|
||||
|
@ -21,18 +21,18 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
});
|
||||
});
|
||||
|
||||
app.get('/stats', (req, res) => {
|
||||
app.get('/stats', (req:any, res:any) => {
|
||||
res.json(require('../../stats').toJSON());
|
||||
});
|
||||
|
||||
app.get('/javascript', (req, res) => {
|
||||
app.get('/javascript', (req:any, res:any) => {
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/javascript.html', {req}));
|
||||
});
|
||||
|
||||
app.get('/robots.txt', (req, res) => {
|
||||
app.get('/robots.txt', (req:any, res:any) => {
|
||||
let filePath =
|
||||
path.join(settings.root, 'src', 'static', 'skins', settings.skinName, 'robots.txt');
|
||||
res.sendFile(filePath, (err) => {
|
||||
res.sendFile(filePath, (err:any) => {
|
||||
// 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');
|
||||
|
@ -41,7 +41,7 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
});
|
||||
});
|
||||
|
||||
app.get('/favicon.ico', (req, res, next) => {
|
||||
app.get('/favicon.ico', (req:any, res:any, next:Function) => {
|
||||
(async () => {
|
||||
/*
|
||||
If this is a url we simply redirect to that one.
|
||||
|
@ -73,14 +73,14 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
});
|
||||
};
|
||||
|
||||
exports.expressCreateServer = (hookName, args, cb) => {
|
||||
exports.expressCreateServer = (hookName:string, args:any, cb:Function) => {
|
||||
// serve index.html under /
|
||||
args.app.get('/', (req, res) => {
|
||||
args.app.get('/', (req:any, res:any) => {
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/index.html', {req}));
|
||||
});
|
||||
|
||||
// serve pad.html under /p
|
||||
args.app.get('/p/:pad', (req, res, next) => {
|
||||
args.app.get('/p/:pad', (req:any, res:any, next:Function) => {
|
||||
// The below might break for pads being rewritten
|
||||
const isReadOnly = !webaccess.userCanModify(req.params.pad, req);
|
||||
|
||||
|
@ -99,7 +99,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
|||
});
|
||||
|
||||
// serve timeslider.html under /p/$padname/timeslider
|
||||
args.app.get('/p/:pad/timeslider', (req, res, next) => {
|
||||
args.app.get('/p/:pad/timeslider', (req:any, res:any, next:Function) => {
|
||||
hooks.callAll('padInitToolbar', {
|
||||
toolbar,
|
||||
});
|
||||
|
@ -112,7 +112,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
|||
|
||||
// The client occasionally polls this endpoint to get an updated expiration for the express_sid
|
||||
// cookie. This handler must be installed after the express-session middleware.
|
||||
args.app.put('/_extendExpressSessionLifetime', (req, res) => {
|
||||
args.app.put('/_extendExpressSessionLifetime', (req:any, res:any) => {
|
||||
// express-session automatically calls req.session.touch() so we don't need to do it here.
|
||||
res.json({status: 'ok'});
|
||||
});
|
|
@ -1,5 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
import {MapArrayType} from "../../types/MapType";
|
||||
import {PartType} from "../../types/PartType";
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const minify = require('../../utils/Minify');
|
||||
const path = require('path');
|
||||
|
@ -10,16 +13,17 @@ 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 tar = {};
|
||||
for (const [key, relativeFiles] of Object.entries(JSON.parse(tarJson))) {
|
||||
const tar:MapArrayType<string[]> = {};
|
||||
for (const [key, relativeFiles] of Object.entries(JSON.parse(tarJson)) as [string, string[]][]) {
|
||||
const files = relativeFiles.map(prefixLocalLibraryPath);
|
||||
tar[prefixLocalLibraryPath(key)] = files
|
||||
.concat(files.map((p) => p.replace(/\.js$/, '')))
|
||||
|
@ -28,7 +32,7 @@ const getTar = async () => {
|
|||
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 +62,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);
|
||||
const clientPlugins = {};
|
||||
for (const name of new Set(clientParts.map((part) => part.plugin))) {
|
||||
app.get('/pluginfw/plugin-definitions.json', (req: any, res:any, next:Function) => {
|
||||
const clientParts = plugins.parts.filter((part: PartType) => part.client_hooks != null);
|
||||
const clientPlugins:MapArrayType<string> = {};
|
||||
for (const name of new Set(clientParts.map((part: PartType) => part.plugin))) {
|
||||
// @ts-ignore
|
||||
clientPlugins[name] = {...plugins.plugins[name]};
|
||||
// @ts-ignore
|
||||
delete clientPlugins[name].package;
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
@ -1,5 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
import {Dirent} from "node:fs";
|
||||
import {PluginDef} from "../../types/PartType";
|
||||
|
||||
const path = require('path');
|
||||
const fsp = require('fs').promises;
|
||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||
|
@ -8,15 +11,15 @@ const settings = require('../../utils/Settings');
|
|||
|
||||
// Returns all *.js files under specDir (recursively) as relative paths to specDir, using '/'
|
||||
// instead of path.sep to separate pathname components.
|
||||
const findSpecs = async (specDir) => {
|
||||
let dirents;
|
||||
const findSpecs = async (specDir: string) => {
|
||||
let dirents: Dirent[];
|
||||
try {
|
||||
dirents = await fsp.readdir(specDir, {withFileTypes: true});
|
||||
} catch (err) {
|
||||
} catch (err:any) {
|
||||
if (['ENOENT', 'ENOTDIR'].includes(err.code)) return [];
|
||||
throw err;
|
||||
}
|
||||
const specs = [];
|
||||
const specs: string[] = [];
|
||||
await Promise.all(dirents.map(async (dirent) => {
|
||||
if (dirent.isDirectory()) {
|
||||
const subdirSpecs = await findSpecs(path.join(specDir, dirent.name));
|
||||
|
@ -29,12 +32,12 @@ const findSpecs = async (specDir) => {
|
|||
return specs;
|
||||
};
|
||||
|
||||
exports.expressPreSession = async (hookName, {app}) => {
|
||||
app.get('/tests/frontend/frontendTestSpecs.json', (req, res, next) => {
|
||||
exports.expressPreSession = async (hookName:string, {app}:any) => {
|
||||
app.get('/tests/frontend/frontendTestSpecs.json', (req:any, res:any, next:Function) => {
|
||||
(async () => {
|
||||
const modules = [];
|
||||
const modules:string[] = [];
|
||||
await Promise.all(Object.entries(plugins.plugins).map(async ([plugin, def]) => {
|
||||
let {package: {path: pluginPath}} = def;
|
||||
let {package: {path: pluginPath}} = def as PluginDef;
|
||||
if (!pluginPath.endsWith(path.sep)) pluginPath += path.sep;
|
||||
const specDir = `${plugin === 'ep_etherpad-lite' ? '' : 'static/'}tests/frontend/specs`;
|
||||
for (const spec of await findSpecs(path.join(pluginPath, specDir))) {
|
||||
|
@ -59,14 +62,14 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
|
||||
const rootTestFolder = path.join(settings.root, 'src/tests/frontend/');
|
||||
|
||||
app.get('/tests/frontend/index.html', (req, res) => {
|
||||
app.get('/tests/frontend/index.html', (req:any, res:any) => {
|
||||
res.redirect(['./', ...req.url.split('?').slice(1)].join('?'));
|
||||
});
|
||||
|
||||
// The regexp /[\d\D]{0,}/ is equivalent to the regexp /.*/. The Express route path used here
|
||||
// uses the more verbose /[\d\D]{0,}/ pattern instead of /.*/ because path-to-regexp v0.1.7 (the
|
||||
// version used with Express v4.x) interprets '.' and '*' differently than regexp.
|
||||
app.get('/tests/frontend/:file([\\d\\D]{0,})', (req, res, next) => {
|
||||
app.get('/tests/frontend/:file([\\d\\D]{0,})', (req:any, res:any, next:Function) => {
|
||||
(async () => {
|
||||
let file = sanitizePathname(req.params.file);
|
||||
if (['', '.', './'].includes(file)) file = 'index.html';
|
||||
|
@ -74,7 +77,7 @@ exports.expressPreSession = async (hookName, {app}) => {
|
|||
})().catch((err) => next(err || new Error(err)));
|
||||
});
|
||||
|
||||
app.get('/tests/frontend', (req, res) => {
|
||||
app.get('/tests/frontend', (req:any, res:any) => {
|
||||
res.redirect(['./frontend/', ...req.url.split('?').slice(1)].join('?'));
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue