diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-16 11:33:22 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 6702a1b2ccd666285dee9c72b5bace641d2fce8b (patch) | |
tree | 78b7125d664b6f6b6c993c4e8483e1bdd24a0a30 /server/middlewares/validators/plugins.ts | |
parent | 503c6f440abc8f5924c38c4bd63591cb6cefacec (diff) | |
download | PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.gz PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.zst PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.zip |
Add ability to search available plugins
Diffstat (limited to 'server/middlewares/validators/plugins.ts')
-rw-r--r-- | server/middlewares/validators/plugins.ts | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index 8103ec7d3..8cb3153aa 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts | |||
@@ -8,6 +8,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 { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' | 9 | import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' |
10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
11 | import { CONFIG } from '../../initializers/config' | ||
11 | 12 | ||
12 | const servePluginStaticDirectoryValidator = (pluginType: PluginType) => [ | 13 | const servePluginStaticDirectoryValidator = (pluginType: PluginType) => [ |
13 | param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'), | 14 | param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'), |
@@ -33,7 +34,7 @@ const servePluginStaticDirectoryValidator = (pluginType: PluginType) => [ | |||
33 | ] | 34 | ] |
34 | 35 | ||
35 | const listPluginsValidator = [ | 36 | const listPluginsValidator = [ |
36 | query('type') | 37 | query('pluginType') |
37 | .optional() | 38 | .optional() |
38 | .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), | 39 | .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), |
39 | query('uninstalled') | 40 | query('uninstalled') |
@@ -119,12 +120,39 @@ const updatePluginSettingsValidator = [ | |||
119 | } | 120 | } |
120 | ] | 121 | ] |
121 | 122 | ||
123 | const listAvailablePluginsValidator = [ | ||
124 | query('sort') | ||
125 | .optional() | ||
126 | .exists().withMessage('Should have a valid sort'), | ||
127 | query('search') | ||
128 | .optional() | ||
129 | .exists().withMessage('Should have a valid search'), | ||
130 | query('pluginType') | ||
131 | .optional() | ||
132 | .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), | ||
133 | |||
134 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
135 | logger.debug('Checking enabledPluginValidator parameters', { parameters: req.query }) | ||
136 | |||
137 | if (areValidationErrors(req, res)) return | ||
138 | |||
139 | if (CONFIG.PLUGINS.INDEX.ENABLED === false) { | ||
140 | return res.status(400) | ||
141 | .json({ error: 'Plugin index is not enabled' }) | ||
142 | .end() | ||
143 | } | ||
144 | |||
145 | return next() | ||
146 | } | ||
147 | ] | ||
148 | |||
122 | // --------------------------------------------------------------------------- | 149 | // --------------------------------------------------------------------------- |
123 | 150 | ||
124 | export { | 151 | export { |
125 | servePluginStaticDirectoryValidator, | 152 | servePluginStaticDirectoryValidator, |
126 | updatePluginSettingsValidator, | 153 | updatePluginSettingsValidator, |
127 | uninstallPluginValidator, | 154 | uninstallPluginValidator, |
155 | listAvailablePluginsValidator, | ||
128 | existingPluginValidator, | 156 | existingPluginValidator, |
129 | installOrUpdatePluginValidator, | 157 | installOrUpdatePluginValidator, |
130 | listPluginsValidator | 158 | listPluginsValidator |