From 4bbfc6c606c8d3794bae25c64c516120af41f4eb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Jun 2018 11:29:23 +0200 Subject: API: Add ability to update video channel avatar --- server/middlewares/validators/avatar.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 server/middlewares/validators/avatar.ts (limited to 'server/middlewares/validators/avatar.ts') 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 @@ +import * as express from 'express' +import { body } from 'express-validator/check' +import { isAvatarFile } from '../../helpers/custom-validators/users' +import { areValidationErrors } from './utils' +import { CONSTRAINTS_FIELDS } from '../../initializers' +import { logger } from '../../helpers/logger' + +const updateAvatarValidator = [ + body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( + 'This file is not supported or too large. Please, make sure it is of the following type : ' + + CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ') + ), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking updateAvatarValidator parameters', { files: req.files }) + + if (areValidationErrors(req, res)) return + + return next() + } +] + +export { + updateAvatarValidator +} -- cgit v1.2.3