diff options
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r-- | server/middlewares/validators/users.ts | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index db40a5c88..42ebddd56 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -3,12 +3,14 @@ import 'express-validator' | |||
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param } from 'express-validator/check' |
4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
5 | import { | 5 | import { |
6 | isAvatarFile, | ||
6 | isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, | 7 | isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, |
7 | isUserVideoQuotaValid | 8 | isUserVideoQuotaValid |
8 | } from '../../helpers/custom-validators/users' | 9 | } from '../../helpers/custom-validators/users' |
9 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 10 | import { isVideoExist, isVideoFile } from '../../helpers/custom-validators/videos' |
10 | import { logger } from '../../helpers/logger' | 11 | import { logger } from '../../helpers/logger' |
11 | import { isSignupAllowed } from '../../helpers/utils' | 12 | import { isSignupAllowed } from '../../helpers/utils' |
13 | import { CONSTRAINTS_FIELDS } from '../../initializers' | ||
12 | import { UserModel } from '../../models/account/user' | 14 | import { UserModel } from '../../models/account/user' |
13 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './utils' |
14 | 16 | ||
@@ -96,6 +98,21 @@ const usersUpdateMeValidator = [ | |||
96 | } | 98 | } |
97 | ] | 99 | ] |
98 | 100 | ||
101 | const usersUpdateMyAvatarValidator = [ | ||
102 | body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( | ||
103 | 'This file is not supported. Please, make sure it is of the following type : ' | ||
104 | + CONSTRAINTS_FIELDS.ACTOR.AVATAR.EXTNAME.join(', ') | ||
105 | ), | ||
106 | |||
107 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
108 | logger.debug('Checking usersUpdateMyAvatarValidator parameters', { parameters: req.body }) | ||
109 | |||
110 | if (areValidationErrors(req, res)) return | ||
111 | |||
112 | return next() | ||
113 | } | ||
114 | ] | ||
115 | |||
99 | const usersGetValidator = [ | 116 | const usersGetValidator = [ |
100 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), | 117 | param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), |
101 | 118 | ||
@@ -145,7 +162,8 @@ export { | |||
145 | usersUpdateMeValidator, | 162 | usersUpdateMeValidator, |
146 | usersVideoRatingValidator, | 163 | usersVideoRatingValidator, |
147 | ensureUserRegistrationAllowed, | 164 | ensureUserRegistrationAllowed, |
148 | usersGetValidator | 165 | usersGetValidator, |
166 | usersUpdateMyAvatarValidator | ||
149 | } | 167 | } |
150 | 168 | ||
151 | // --------------------------------------------------------------------------- | 169 | // --------------------------------------------------------------------------- |