]>
Commit | Line | Data |
---|---|---|
345da516 | 1 | import * as express from 'express' |
c8861d5d | 2 | import { param } from 'express-validator' |
345da516 C |
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' | |
2d53be02 | 8 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
345da516 C |
9 | |
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'), | |
14 | ||
15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
16 | logger.debug('Checking serveThemeCSS parameters', { parameters: req.params }) | |
17 | ||
18 | if (areValidationErrors(req, res)) return | |
19 | ||
e1c55031 | 20 | const theme = PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName) |
345da516 C |
21 | |
22 | if (!theme || theme.version !== req.params.themeVersion) { | |
2d53be02 | 23 | return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
345da516 C |
24 | } |
25 | ||
26 | if (theme.css.includes(req.params.staticEndpoint) === false) { | |
2d53be02 | 27 | return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
345da516 C |
28 | } |
29 | ||
30 | res.locals.registeredPlugin = theme | |
31 | ||
32 | return next() | |
33 | } | |
34 | ] | |
35 | ||
36 | // --------------------------------------------------------------------------- | |
37 | ||
38 | export { | |
39 | serveThemeCSSValidator | |
40 | } |