diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-29 11:29:23 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-29 11:29:23 +0200 |
commit | 4bbfc6c606c8d3794bae25c64c516120af41f4eb (patch) | |
tree | 8d6012f3c04e55e7325e3f00eb9061776cc7a953 /server/middlewares/validators | |
parent | 3ff5a19b4c988d6c712b7ce63c4cf04f99d047ce (diff) | |
download | PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.tar.gz PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.tar.zst PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.zip |
API: Add ability to update video channel avatar
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/avatar.ts | 25 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 21 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 2 |
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { body } from 'express-validator/check' | ||
3 | import { isAvatarFile } from '../../helpers/custom-validators/users' | ||
4 | import { areValidationErrors } from './utils' | ||
5 | import { CONSTRAINTS_FIELDS } from '../../initializers' | ||
6 | import { logger } from '../../helpers/logger' | ||
7 | |||
8 | const 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 | |||
23 | export { | ||
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' | |||
5 | import { omit } from 'lodash' | 5 | import { omit } from 'lodash' |
6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
7 | import { | 7 | import { |
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 { | |||
17 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 17 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
18 | import { logger } from '../../helpers/logger' | 18 | import { logger } from '../../helpers/logger' |
19 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils' | 19 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils' |
20 | import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' | ||
21 | import { Redis } from '../../lib/redis' | 20 | import { Redis } from '../../lib/redis' |
22 | import { UserModel } from '../../models/account/user' | 21 | import { UserModel } from '../../models/account/user' |
23 | import { areValidationErrors } from './utils' | 22 | import { areValidationErrors } from './utils' |
@@ -116,21 +115,6 @@ const usersUpdateMeValidator = [ | |||
116 | } | 115 | } |
117 | ] | 116 | ] |
118 | 117 | ||
119 | const 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 | |||
134 | const usersGetValidator = [ | 118 | const 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' | |||
13 | import { UserModel } from '../../models/account/user' | 13 | import { UserModel } from '../../models/account/user' |
14 | import { VideoChannelModel } from '../../models/video/video-channel' | 14 | import { VideoChannelModel } from '../../models/video/video-channel' |
15 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './utils' |
16 | import { isAvatarFile } from '../../helpers/custom-validators/users' | ||
17 | import { CONSTRAINTS_FIELDS } from '../../initializers' | ||
16 | 18 | ||
17 | const listVideoAccountChannelsValidator = [ | 19 | const listVideoAccountChannelsValidator = [ |
18 | param('accountName').exists().withMessage('Should have a valid account name'), | 20 | param('accountName').exists().withMessage('Should have a valid account name'), |