]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { param } from 'express-validator' |
c0e8b12e | 3 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
10363c74 | 4 | import { isSafePath } from '../../helpers/custom-validators/misc' |
345da516 | 5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' |
10363c74 | 6 | import { logger } from '../../helpers/logger' |
345da516 | 7 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
10363c74 | 8 | import { areValidationErrors } from './shared' |
345da516 C |
9 | |
10 | const serveThemeCSSValidator = [ | |
396f6f01 C |
11 | param('themeName') |
12 | .custom(isPluginNameValid), | |
13 | param('themeVersion') | |
14 | .custom(isPluginVersionValid), | |
15 | param('staticEndpoint') | |
16 | .custom(isSafePath), | |
345da516 C |
17 | |
18 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
19 | logger.debug('Checking serveThemeCSS parameters', { parameters: req.params }) | |
20 | ||
21 | if (areValidationErrors(req, res)) return | |
22 | ||
e1c55031 | 23 | const theme = PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName) |
345da516 C |
24 | |
25 | if (!theme || theme.version !== req.params.themeVersion) { | |
76148b27 RK |
26 | return res.fail({ |
27 | status: HttpStatusCode.NOT_FOUND_404, | |
28 | message: 'No theme named ' + req.params.themeName + ' was found with version ' + req.params.themeVersion | |
29 | }) | |
345da516 C |
30 | } |
31 | ||
32 | if (theme.css.includes(req.params.staticEndpoint) === false) { | |
76148b27 RK |
33 | return res.fail({ |
34 | status: HttpStatusCode.NOT_FOUND_404, | |
35 | message: 'No static endpoint was found for this theme' | |
36 | }) | |
345da516 C |
37 | } |
38 | ||
39 | res.locals.registeredPlugin = theme | |
40 | ||
41 | return next() | |
42 | } | |
43 | ] | |
44 | ||
45 | // --------------------------------------------------------------------------- | |
46 | ||
47 | export { | |
48 | serveThemeCSSValidator | |
49 | } |