]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/themes.ts
Translated using Weblate (Vietnamese)
[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'
ff91b644 5import { isPluginNameValid, isPluginStableOrUnstableVersionValid } from '../../helpers/custom-validators/plugins'
345da516 6import { PluginManager } from '../../lib/plugins/plugin-manager'
10363c74 7import { areValidationErrors } from './shared'
345da516
C
8
9const serveThemeCSSValidator = [
396f6f01
C
10 param('themeName')
11 .custom(isPluginNameValid),
12 param('themeVersion')
ff91b644 13 .custom(isPluginStableOrUnstableVersionValid),
396f6f01
C
14 param('staticEndpoint')
15 .custom(isSafePath),
345da516
C
16
17 (req: express.Request, res: express.Response, next: express.NextFunction) => {
345da516
C
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) {
76148b27
RK
23 return res.fail({
24 status: HttpStatusCode.NOT_FOUND_404,
25 message: 'No theme named ' + req.params.themeName + ' was found with version ' + req.params.themeVersion
26 })
345da516
C
27 }
28
29 if (theme.css.includes(req.params.staticEndpoint) === false) {
76148b27
RK
30 return res.fail({
31 status: HttpStatusCode.NOT_FOUND_404,
32 message: 'No static endpoint was found for this theme'
33 })
345da516
C
34 }
35
36 res.locals.registeredPlugin = theme
37
38 return next()
39 }
40]
41
42// ---------------------------------------------------------------------------
43
44export {
45 serveThemeCSSValidator
46}