diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-17 14:27:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-17 14:27:04 +0200 |
commit | 396f6f0140b0f76162e2378fd5a61e2f888673ed (patch) | |
tree | a5bd668bfc7dca7f311b9fc42ebb8bd01f462648 /server/middlewares/validators/plugins.ts | |
parent | 97eba003a9d0adcb0cab9190f566327b1417c7d3 (diff) | |
download | PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.tar.gz PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.tar.zst PeerTube-396f6f0140b0f76162e2378fd5a61e2f888673ed.zip |
Cleanup useless express validator messages
Diffstat (limited to 'server/middlewares/validators/plugins.ts')
-rw-r--r-- | server/middlewares/validators/plugins.ts | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index c1e9ebefb..dc80469c3 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts | |||
@@ -13,12 +13,14 @@ import { areValidationErrors } from './shared' | |||
13 | 13 | ||
14 | const getPluginValidator = (pluginType: PluginType, withVersion = true) => { | 14 | const getPluginValidator = (pluginType: PluginType, withVersion = true) => { |
15 | const validators: (ValidationChain | express.Handler)[] = [ | 15 | const validators: (ValidationChain | express.Handler)[] = [ |
16 | param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name') | 16 | param('pluginName') |
17 | .custom(isPluginNameValid) | ||
17 | ] | 18 | ] |
18 | 19 | ||
19 | if (withVersion) { | 20 | if (withVersion) { |
20 | validators.push( | 21 | validators.push( |
21 | param('pluginVersion').custom(isPluginVersionValid).withMessage('Should have a valid plugin version') | 22 | param('pluginVersion') |
23 | .custom(isPluginVersionValid) | ||
22 | ) | 24 | ) |
23 | } | 25 | } |
24 | 26 | ||
@@ -52,7 +54,8 @@ const getPluginValidator = (pluginType: PluginType, withVersion = true) => { | |||
52 | } | 54 | } |
53 | 55 | ||
54 | const getExternalAuthValidator = [ | 56 | const getExternalAuthValidator = [ |
55 | param('authName').custom(exists).withMessage('Should have a valid auth name'), | 57 | param('authName') |
58 | .custom(exists), | ||
56 | 59 | ||
57 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 60 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
58 | logger.debug('Checking getExternalAuthValidator parameters', { parameters: req.params }) | 61 | logger.debug('Checking getExternalAuthValidator parameters', { parameters: req.params }) |
@@ -82,7 +85,8 @@ const getExternalAuthValidator = [ | |||
82 | ] | 85 | ] |
83 | 86 | ||
84 | const pluginStaticDirectoryValidator = [ | 87 | const pluginStaticDirectoryValidator = [ |
85 | param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'), | 88 | param('staticEndpoint') |
89 | .custom(isSafePath), | ||
86 | 90 | ||
87 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 91 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
88 | logger.debug('Checking pluginStaticDirectoryValidator parameters', { parameters: req.params }) | 92 | logger.debug('Checking pluginStaticDirectoryValidator parameters', { parameters: req.params }) |
@@ -97,11 +101,11 @@ const listPluginsValidator = [ | |||
97 | query('pluginType') | 101 | query('pluginType') |
98 | .optional() | 102 | .optional() |
99 | .customSanitizer(toIntOrNull) | 103 | .customSanitizer(toIntOrNull) |
100 | .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), | 104 | .custom(isPluginTypeValid), |
101 | query('uninstalled') | 105 | query('uninstalled') |
102 | .optional() | 106 | .optional() |
103 | .customSanitizer(toBooleanOrNull) | 107 | .customSanitizer(toBooleanOrNull) |
104 | .custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'), | 108 | .custom(isBooleanValid), |
105 | 109 | ||
106 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 110 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
107 | logger.debug('Checking listPluginsValidator parameters', { parameters: req.query }) | 111 | logger.debug('Checking listPluginsValidator parameters', { parameters: req.query }) |
@@ -115,13 +119,13 @@ const listPluginsValidator = [ | |||
115 | const installOrUpdatePluginValidator = [ | 119 | const installOrUpdatePluginValidator = [ |
116 | body('npmName') | 120 | body('npmName') |
117 | .optional() | 121 | .optional() |
118 | .custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), | 122 | .custom(isNpmPluginNameValid), |
119 | body('pluginVersion') | 123 | body('pluginVersion') |
120 | .optional() | 124 | .optional() |
121 | .custom(isPluginVersionValid).withMessage('Should have a valid plugin version'), | 125 | .custom(isPluginVersionValid), |
122 | body('path') | 126 | body('path') |
123 | .optional() | 127 | .optional() |
124 | .custom(isSafePath).withMessage('Should have a valid safe path'), | 128 | .custom(isSafePath), |
125 | 129 | ||
126 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 130 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
127 | logger.debug('Checking installOrUpdatePluginValidator parameters', { parameters: req.body }) | 131 | logger.debug('Checking installOrUpdatePluginValidator parameters', { parameters: req.body }) |
@@ -141,7 +145,8 @@ const installOrUpdatePluginValidator = [ | |||
141 | ] | 145 | ] |
142 | 146 | ||
143 | const uninstallPluginValidator = [ | 147 | const uninstallPluginValidator = [ |
144 | body('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), | 148 | body('npmName') |
149 | .custom(isNpmPluginNameValid), | ||
145 | 150 | ||
146 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 151 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
147 | logger.debug('Checking uninstallPluginValidator parameters', { parameters: req.body }) | 152 | logger.debug('Checking uninstallPluginValidator parameters', { parameters: req.body }) |
@@ -153,7 +158,8 @@ const uninstallPluginValidator = [ | |||
153 | ] | 158 | ] |
154 | 159 | ||
155 | const existingPluginValidator = [ | 160 | const existingPluginValidator = [ |
156 | param('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid plugin name'), | 161 | param('npmName') |
162 | .custom(isNpmPluginNameValid), | ||
157 | 163 | ||
158 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 164 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
159 | logger.debug('Checking enabledPluginValidator parameters', { parameters: req.params }) | 165 | logger.debug('Checking enabledPluginValidator parameters', { parameters: req.params }) |
@@ -174,7 +180,8 @@ const existingPluginValidator = [ | |||
174 | ] | 180 | ] |
175 | 181 | ||
176 | const updatePluginSettingsValidator = [ | 182 | const updatePluginSettingsValidator = [ |
177 | body('settings').exists().withMessage('Should have settings'), | 183 | body('settings') |
184 | .exists(), | ||
178 | 185 | ||
179 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 186 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
180 | logger.debug('Checking enabledPluginValidator parameters', { parameters: req.body }) | 187 | logger.debug('Checking enabledPluginValidator parameters', { parameters: req.body }) |
@@ -188,14 +195,14 @@ const updatePluginSettingsValidator = [ | |||
188 | const listAvailablePluginsValidator = [ | 195 | const listAvailablePluginsValidator = [ |
189 | query('search') | 196 | query('search') |
190 | .optional() | 197 | .optional() |
191 | .exists().withMessage('Should have a valid search'), | 198 | .exists(), |
192 | query('pluginType') | 199 | query('pluginType') |
193 | .optional() | 200 | .optional() |
194 | .customSanitizer(toIntOrNull) | 201 | .customSanitizer(toIntOrNull) |
195 | .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), | 202 | .custom(isPluginTypeValid), |
196 | query('currentPeerTubeEngine') | 203 | query('currentPeerTubeEngine') |
197 | .optional() | 204 | .optional() |
198 | .custom(isPluginVersionValid).withMessage('Should have a valid current peertube engine'), | 205 | .custom(isPluginVersionValid), |
199 | 206 | ||
200 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 207 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
201 | logger.debug('Checking enabledPluginValidator parameters', { parameters: req.query }) | 208 | logger.debug('Checking enabledPluginValidator parameters', { parameters: req.query }) |