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 +++++++++++++++++++++++++ server/middlewares/validators/users.ts | 21 ++------------------- server/middlewares/validators/video-channels.ts | 2 ++ 3 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 server/middlewares/validators/avatar.ts (limited to 'server/middlewares') 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 +} 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' import { omit } from 'lodash' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { - isAvatarFile, isUserAutoPlayVideoValid, - isUserDescriptionValid, isUserDisplayNameValid, + isUserDescriptionValid, + isUserDisplayNameValid, isUserNSFWPolicyValid, isUserPasswordValid, isUserRoleValid, @@ -17,7 +17,6 @@ import { import { isVideoExist } from '../../helpers/custom-validators/videos' import { logger } from '../../helpers/logger' import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils' -import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' import { Redis } from '../../lib/redis' import { UserModel } from '../../models/account/user' import { areValidationErrors } from './utils' @@ -116,21 +115,6 @@ const usersUpdateMeValidator = [ } ] -const usersUpdateMyAvatarValidator = [ - 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 usersUpdateMyAvatarValidator parameters', { files: req.files }) - - if (areValidationErrors(req, res)) return - - return next() - } -] - const usersGetValidator = [ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), @@ -239,7 +223,6 @@ export { ensureUserRegistrationAllowed, ensureUserRegistrationAllowedForIP, usersGetValidator, - usersUpdateMyAvatarValidator, usersAskResetPasswordValidator, usersResetPasswordValidator } 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' import { UserModel } from '../../models/account/user' import { VideoChannelModel } from '../../models/video/video-channel' import { areValidationErrors } from './utils' +import { isAvatarFile } from '../../helpers/custom-validators/users' +import { CONSTRAINTS_FIELDS } from '../../initializers' const listVideoAccountChannelsValidator = [ param('accountName').exists().withMessage('Should have a valid account name'), -- cgit v1.2.3