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.ts30
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
8import { PluginModel } from '../../models/server/plugin' 8import { PluginModel } from '../../models/server/plugin'
9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' 9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
10import { PluginType } from '../../../shared/models/plugins/plugin.type' 10import { PluginType } from '../../../shared/models/plugins/plugin.type'
11import { CONFIG } from '../../initializers/config'
11 12
12const servePluginStaticDirectoryValidator = (pluginType: PluginType) => [ 13const 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
35const listPluginsValidator = [ 36const 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
123const 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
124export { 151export {
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