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/avatar.ts | |
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/avatar.ts')
-rw-r--r-- | server/middlewares/validators/avatar.ts | 25 |
1 files changed, 25 insertions, 0 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 | } | ||