]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/themes.ts
Fix socket notification with multiple user tabs
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / themes.ts
CommitLineData
345da516 1import * as express from 'express'
c8861d5d 2import { param } from 'express-validator'
345da516
C
3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils'
5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
6import { PluginManager } from '../../lib/plugins/plugin-manager'
7import { isSafePath } from '../../helpers/custom-validators/misc'
8
9const 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'),
13
14 (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 logger.debug('Checking serveThemeCSS parameters', { parameters: req.params })
16
17 if (areValidationErrors(req, res)) return
18
19 const theme = PluginManager.Instance.getRegisteredTheme(req.params.themeName)
20
21 if (!theme || theme.version !== req.params.themeVersion) {
22 return res.sendStatus(404)
23 }
24
25 if (theme.css.includes(req.params.staticEndpoint) === false) {
26 return res.sendStatus(404)
27 }
28
29 res.locals.registeredPlugin = theme
30
31 return next()
32 }
33]
34
35// ---------------------------------------------------------------------------
36
37export {
38 serveThemeCSSValidator
39}