diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-05 13:54:32 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 345da516fae80f24c90c2196e96393b489af2243 (patch) | |
tree | 64d72d25a531626c1d4a6337460dae4e32386f2a /server/middlewares/validators/themes.ts | |
parent | 297067399db2bf7505561d67667ca0d559a8e42b (diff) | |
download | PeerTube-345da516fae80f24c90c2196e96393b489af2243.tar.gz PeerTube-345da516fae80f24c90c2196e96393b489af2243.tar.zst PeerTube-345da516fae80f24c90c2196e96393b489af2243.zip |
WIP plugins: add ability to register plugins
Diffstat (limited to 'server/middlewares/validators/themes.ts')
-rw-r--r-- | server/middlewares/validators/themes.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts new file mode 100644 index 000000000..642f2df78 --- /dev/null +++ b/server/middlewares/validators/themes.ts | |||
@@ -0,0 +1,39 @@ | |||
1 | import * as express from 'express' | ||
2 | import { param } from 'express-validator/check' | ||
3 | import { logger } from '../../helpers/logger' | ||
4 | import { areValidationErrors } from './utils' | ||
5 | import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | ||
6 | import { PluginManager } from '../../lib/plugins/plugin-manager' | ||
7 | import { isSafePath } from '../../helpers/custom-validators/misc' | ||
8 | |||
9 | const 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 | |||
37 | export { | ||
38 | serveThemeCSSValidator | ||
39 | } | ||