1 import express from 'express'
2 import { param } from 'express-validator'
3 import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
4 import { isSafePath } from '../../helpers/custom-validators/misc'
5 import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
6 import { logger } from '../../helpers/logger'
7 import { PluginManager } from '../../lib/plugins/plugin-manager'
8 import { areValidationErrors } from './shared'
10 const serveThemeCSSValidator = [
11 param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'),
12 param('themeVersion').custom(isPluginVersionValid).withMessage('Should have a valid theme version'),
13 param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'),
15 (req: express.Request, res: express.Response, next: express.NextFunction) => {
16 logger.debug('Checking serveThemeCSS parameters', { parameters: req.params })
18 if (areValidationErrors(req, res)) return
20 const theme = PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName)
22 if (!theme || theme.version !== req.params.themeVersion) {
24 status: HttpStatusCode.NOT_FOUND_404,
25 message: 'No theme named ' + req.params.themeName + ' was found with version ' + req.params.themeVersion
29 if (theme.css.includes(req.params.staticEndpoint) === false) {
31 status: HttpStatusCode.NOT_FOUND_404,
32 message: 'No static endpoint was found for this theme'
36 res.locals.registeredPlugin = theme
42 // ---------------------------------------------------------------------------
45 serveThemeCSSValidator