]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/themes.ts
Cleanup useless express validator messages
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / themes.ts
CommitLineData
41fb13c3 1import express from 'express'
c8861d5d 2import { param } from 'express-validator'
c0e8b12e 3import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
10363c74 4import { isSafePath } from '../../helpers/custom-validators/misc'
345da516 5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
10363c74 6import { logger } from '../../helpers/logger'
345da516 7import { PluginManager } from '../../lib/plugins/plugin-manager'
10363c74 8import { areValidationErrors } from './shared'
345da516
C
9
10const 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
47export {
48 serveThemeCSSValidator
49}