aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/avatar.ts25
-rw-r--r--server/middlewares/validators/users.ts21
-rw-r--r--server/middlewares/validators/video-channels.ts2
3 files changed, 29 insertions, 19 deletions
diff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.ts
new file mode 100644
index 000000000..f346ea92f
--- /dev/null
+++ b/server/middlewares/validators/avatar.ts
@@ -0,0 +1,25 @@
1import * as express from 'express'
2import { body } from 'express-validator/check'
3import { isAvatarFile } from '../../helpers/custom-validators/users'
4import { areValidationErrors } from './utils'
5import { CONSTRAINTS_FIELDS } from '../../initializers'
6import { logger } from '../../helpers/logger'
7
8const updateAvatarValidator = [
9 body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage(
10 'This file is not supported or too large. Please, make sure it is of the following type : '
11 + CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ')
12 ),
13
14 (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 logger.debug('Checking updateAvatarValidator parameters', { files: req.files })
16
17 if (areValidationErrors(req, res)) return
18
19 return next()
20 }
21]
22
23export {
24 updateAvatarValidator
25}
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 55a08a648..8ca9763a1 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -5,9 +5,9 @@ import { body, param } from 'express-validator/check'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 6import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
7import { 7import {
8 isAvatarFile,
9 isUserAutoPlayVideoValid, 8 isUserAutoPlayVideoValid,
10 isUserDescriptionValid, isUserDisplayNameValid, 9 isUserDescriptionValid,
10 isUserDisplayNameValid,
11 isUserNSFWPolicyValid, 11 isUserNSFWPolicyValid,
12 isUserPasswordValid, 12 isUserPasswordValid,
13 isUserRoleValid, 13 isUserRoleValid,
@@ -17,7 +17,6 @@ import {
17import { isVideoExist } from '../../helpers/custom-validators/videos' 17import { isVideoExist } from '../../helpers/custom-validators/videos'
18import { logger } from '../../helpers/logger' 18import { logger } from '../../helpers/logger'
19import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils' 19import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils'
20import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
21import { Redis } from '../../lib/redis' 20import { Redis } from '../../lib/redis'
22import { UserModel } from '../../models/account/user' 21import { UserModel } from '../../models/account/user'
23import { areValidationErrors } from './utils' 22import { areValidationErrors } from './utils'
@@ -116,21 +115,6 @@ const usersUpdateMeValidator = [
116 } 115 }
117] 116]
118 117
119const usersUpdateMyAvatarValidator = [
120 body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage(
121 'This file is not supported or too large. Please, make sure it is of the following type : '
122 + CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ')
123 ),
124
125 (req: express.Request, res: express.Response, next: express.NextFunction) => {
126 logger.debug('Checking usersUpdateMyAvatarValidator parameters', { files: req.files })
127
128 if (areValidationErrors(req, res)) return
129
130 return next()
131 }
132]
133
134const usersGetValidator = [ 118const usersGetValidator = [
135 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), 119 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'),
136 120
@@ -239,7 +223,6 @@ export {
239 ensureUserRegistrationAllowed, 223 ensureUserRegistrationAllowed,
240 ensureUserRegistrationAllowedForIP, 224 ensureUserRegistrationAllowedForIP,
241 usersGetValidator, 225 usersGetValidator,
242 usersUpdateMyAvatarValidator,
243 usersAskResetPasswordValidator, 226 usersAskResetPasswordValidator,
244 usersResetPasswordValidator 227 usersResetPasswordValidator
245} 228}
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index a5be5f114..7f65f7290 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -13,6 +13,8 @@ import { logger } from '../../helpers/logger'
13import { UserModel } from '../../models/account/user' 13import { UserModel } from '../../models/account/user'
14import { VideoChannelModel } from '../../models/video/video-channel' 14import { VideoChannelModel } from '../../models/video/video-channel'
15import { areValidationErrors } from './utils' 15import { areValidationErrors } from './utils'
16import { isAvatarFile } from '../../helpers/custom-validators/users'
17import { CONSTRAINTS_FIELDS } from '../../initializers'
16 18
17const listVideoAccountChannelsValidator = [ 19const listVideoAccountChannelsValidator = [
18 param('accountName').exists().withMessage('Should have a valid account name'), 20 param('accountName').exists().withMessage('Should have a valid account name'),