aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/plugins.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-12 11:39:58 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commitb5f919ac8eb2a1c20e26582fdfd377d687710d8f (patch)
tree5ec28be6f750f54bba560803ddba681103c2d82e /server/middlewares/validators/plugins.ts
parent8d2be0ed7bb87283a1ec98609df6b82d83db706a (diff)
downloadPeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.gz
PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.zst
PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.zip
WIP plugins: update plugin
Diffstat (limited to 'server/middlewares/validators/plugins.ts')
-rw-r--r--server/middlewares/validators/plugins.ts20
1 files changed, 11 insertions, 9 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index a1634ded4..8103ec7d3 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -1,14 +1,15 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param, query, body } from 'express-validator/check' 2import { body, param, query } from 'express-validator/check'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { isPluginNameValid, isPluginTypeValid, isPluginVersionValid, isNpmPluginNameValid } from '../../helpers/custom-validators/plugins' 5import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
6import { PluginManager } from '../../lib/plugins/plugin-manager' 6import { PluginManager } from '../../lib/plugins/plugin-manager'
7import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc' 7import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc'
8import { PluginModel } from '../../models/server/plugin' 8import { PluginModel } from '../../models/server/plugin'
9import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model' 9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
10import { PluginType } from '../../../shared/models/plugins/plugin.type'
10 11
11const servePluginStaticDirectoryValidator = [ 12const servePluginStaticDirectoryValidator = (pluginType: PluginType) => [
12 param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'), 13 param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'),
13 param('pluginVersion').custom(isPluginVersionValid).withMessage('Should have a valid plugin version'), 14 param('pluginVersion').custom(isPluginVersionValid).withMessage('Should have a valid plugin version'),
14 param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'), 15 param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'),
@@ -18,7 +19,8 @@ const servePluginStaticDirectoryValidator = [
18 19
19 if (areValidationErrors(req, res)) return 20 if (areValidationErrors(req, res)) return
20 21
21 const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(req.params.pluginName) 22 const npmName = PluginModel.buildNpmName(req.params.pluginName, pluginType)
23 const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(npmName)
22 24
23 if (!plugin || plugin.version !== req.params.pluginVersion) { 25 if (!plugin || plugin.version !== req.params.pluginVersion) {
24 return res.sendStatus(404) 26 return res.sendStatus(404)
@@ -48,7 +50,7 @@ const listPluginsValidator = [
48 } 50 }
49] 51]
50 52
51const installPluginValidator = [ 53const installOrUpdatePluginValidator = [
52 body('npmName') 54 body('npmName')
53 .optional() 55 .optional()
54 .custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), 56 .custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'),
@@ -57,11 +59,11 @@ const installPluginValidator = [
57 .custom(isSafePath).withMessage('Should have a valid safe path'), 59 .custom(isSafePath).withMessage('Should have a valid safe path'),
58 60
59 (req: express.Request, res: express.Response, next: express.NextFunction) => { 61 (req: express.Request, res: express.Response, next: express.NextFunction) => {
60 logger.debug('Checking installPluginValidator parameters', { parameters: req.body }) 62 logger.debug('Checking installOrUpdatePluginValidator parameters', { parameters: req.body })
61 63
62 if (areValidationErrors(req, res)) return 64 if (areValidationErrors(req, res)) return
63 65
64 const body: InstallPlugin = req.body 66 const body: InstallOrUpdatePlugin = req.body
65 if (!body.path && !body.npmName) { 67 if (!body.path && !body.npmName) {
66 return res.status(400) 68 return res.status(400)
67 .json({ error: 'Should have either a npmName or a path' }) 69 .json({ error: 'Should have either a npmName or a path' })
@@ -124,6 +126,6 @@ export {
124 updatePluginSettingsValidator, 126 updatePluginSettingsValidator,
125 uninstallPluginValidator, 127 uninstallPluginValidator,
126 existingPluginValidator, 128 existingPluginValidator,
127 installPluginValidator, 129 installOrUpdatePluginValidator,
128 listPluginsValidator 130 listPluginsValidator
129} 131}