diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/plugins.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index a06add6b8..a1634ded4 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts | |||
@@ -6,6 +6,7 @@ import { isPluginNameValid, isPluginTypeValid, isPluginVersionValid, isNpmPlugin | |||
6 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 6 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
7 | import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc' | 7 | import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc' |
8 | import { PluginModel } from '../../models/server/plugin' | 8 | import { PluginModel } from '../../models/server/plugin' |
9 | import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model' | ||
9 | 10 | ||
10 | const servePluginStaticDirectoryValidator = [ | 11 | const servePluginStaticDirectoryValidator = [ |
11 | param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'), | 12 | param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'), |
@@ -48,13 +49,25 @@ const listPluginsValidator = [ | |||
48 | ] | 49 | ] |
49 | 50 | ||
50 | const installPluginValidator = [ | 51 | const installPluginValidator = [ |
51 | body('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), | 52 | body('npmName') |
53 | .optional() | ||
54 | .custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), | ||
55 | body('path') | ||
56 | .optional() | ||
57 | .custom(isSafePath).withMessage('Should have a valid safe path'), | ||
52 | 58 | ||
53 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 59 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
54 | logger.debug('Checking installPluginValidator parameters', { parameters: req.body }) | 60 | logger.debug('Checking installPluginValidator parameters', { parameters: req.body }) |
55 | 61 | ||
56 | if (areValidationErrors(req, res)) return | 62 | if (areValidationErrors(req, res)) return |
57 | 63 | ||
64 | const body: InstallPlugin = req.body | ||
65 | if (!body.path && !body.npmName) { | ||
66 | return res.status(400) | ||
67 | .json({ error: 'Should have either a npmName or a path' }) | ||
68 | .end() | ||
69 | } | ||
70 | |||
58 | return next() | 71 | return next() |
59 | } | 72 | } |
60 | ] | 73 | ] |