X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fthemes.ts;h=080b3e096303fc12c8d2c73e0039b8465063eac2;hb=ff91b644fb1b063d0a8eff7492beb1a9bf7e4ce1;hp=24a9673f788d5c08194a3cecf81e518b5d77626a;hpb=c8861d5dc0436ef4342ce517241e3591fa256a13;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts index 24a9673f7..080b3e096 100644 --- a/server/middlewares/validators/themes.ts +++ b/server/middlewares/validators/themes.ts @@ -1,29 +1,36 @@ -import * as express from 'express' +import express from 'express' import { param } from 'express-validator' -import { logger } from '../../helpers/logger' -import { areValidationErrors } from './utils' -import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' -import { PluginManager } from '../../lib/plugins/plugin-manager' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { isSafePath } from '../../helpers/custom-validators/misc' +import { isPluginNameValid, isPluginStableOrUnstableVersionValid } from '../../helpers/custom-validators/plugins' +import { PluginManager } from '../../lib/plugins/plugin-manager' +import { areValidationErrors } from './shared' const serveThemeCSSValidator = [ - param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'), - param('themeVersion').custom(isPluginVersionValid).withMessage('Should have a valid theme version'), - param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'), + param('themeName') + .custom(isPluginNameValid), + param('themeVersion') + .custom(isPluginStableOrUnstableVersionValid), + param('staticEndpoint') + .custom(isSafePath), (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking serveThemeCSS parameters', { parameters: req.params }) - if (areValidationErrors(req, res)) return - const theme = PluginManager.Instance.getRegisteredTheme(req.params.themeName) + const theme = PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName) if (!theme || theme.version !== req.params.themeVersion) { - return res.sendStatus(404) + return res.fail({ + status: HttpStatusCode.NOT_FOUND_404, + message: 'No theme named ' + req.params.themeName + ' was found with version ' + req.params.themeVersion + }) } if (theme.css.includes(req.params.staticEndpoint) === false) { - return res.sendStatus(404) + return res.fail({ + status: HttpStatusCode.NOT_FOUND_404, + message: 'No static endpoint was found for this theme' + }) } res.locals.registeredPlugin = theme