1 import * as express from 'express'
2 import { param } from 'express-validator'
3 import { logger } from '../../helpers/logger'
4 import { areValidationErrors } from './utils'
5 import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
6 import { PluginManager } from '../../lib/plugins/plugin-manager'
7 import { isSafePath } from '../../helpers/custom-validators/misc'
9 const serveThemeCSSValidator = [
10 param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'),
11 param('themeVersion').custom(isPluginVersionValid).withMessage('Should have a valid theme version'),
12 param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'),
14 (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 logger.debug('Checking serveThemeCSS parameters', { parameters: req.params })
17 if (areValidationErrors(req, res)) return
19 const theme = PluginManager.Instance.getRegisteredTheme(req.params.themeName)
21 if (!theme || theme.version !== req.params.themeVersion) {
22 return res.sendStatus(404)
25 if (theme.css.includes(req.params.staticEndpoint) === false) {
26 return res.sendStatus(404)
29 res.locals.registeredPlugin = theme
35 // ---------------------------------------------------------------------------
38 serveThemeCSSValidator