diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-11 17:23:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 8d2be0ed7bb87283a1ec98609df6b82d83db706a (patch) | |
tree | 31a36b252df32be83ceb77658a53b57f9d15e8ac /server/middlewares/validators/plugins.ts | |
parent | dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (diff) | |
download | PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.gz PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.zst PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.zip |
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
Diffstat (limited to 'server/middlewares/validators/plugins.ts')
-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 | ] |