aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/plugins.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/plugins.ts')
-rw-r--r--server/middlewares/validators/plugins.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
new file mode 100644
index 000000000..672299ee1
--- /dev/null
+++ b/server/middlewares/validators/plugins.ts
@@ -0,0 +1,35 @@
1import * as express from 'express'
2import { param } from 'express-validator/check'
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 servePluginStaticDirectoryValidator = [
10 param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'),
11 param('pluginVersion').custom(isPluginVersionValid).withMessage('Should have a valid plugin 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 servePluginStaticDirectory parameters', { parameters: req.params })
16
17 if (areValidationErrors(req, res)) return
18
19 const plugin = PluginManager.Instance.getRegisteredPlugin(req.params.pluginName)
20
21 if (!plugin || plugin.version !== req.params.pluginVersion) {
22 return res.sendStatus(404)
23 }
24
25 res.locals.registeredPlugin = plugin
26
27 return next()
28 }
29]
30
31// ---------------------------------------------------------------------------
32
33export {
34 servePluginStaticDirectoryValidator
35}