From 2cb03dc1f4e01ba491c36caff30c33fe9c5bad89 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Apr 2021 17:01:35 +0200 Subject: Add banners support --- server/middlewares/validators/avatar.ts | 16 ++++++++++------ server/middlewares/validators/follows.ts | 1 - server/middlewares/validators/videos/video-channels.ts | 2 -- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.ts index 2acb97483..f7eb367bd 100644 --- a/server/middlewares/validators/avatar.ts +++ b/server/middlewares/validators/avatar.ts @@ -6,21 +6,25 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { logger } from '../../helpers/logger' import { cleanUpReqFiles } from '../../helpers/express-utils' -const updateAvatarValidator = [ - body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( +const updateActorImageValidatorFactory = (fieldname: string) => ([ + body(fieldname).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(', ') + CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ') ), (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking updateAvatarValidator parameters', { files: req.files }) + logger.debug('Checking updateActorImageValidator parameters', { files: req.files }) if (areValidationErrors(req, res)) return cleanUpReqFiles(req) return next() } -] +]) + +const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile') +const updateBannerValidator = updateActorImageValidatorFactory('bannerfile') export { - updateAvatarValidator + updateAvatarValidator, + updateBannerValidator } diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index a590aca99..bb849dc72 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -68,7 +68,6 @@ const removeFollowingValidator = [ .json({ error: `Following ${req.params.host} not found.` }) - .end() } res.locals.follow = follow diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index 57ac548b9..2463d281c 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -73,13 +73,11 @@ const videoChannelsUpdateValidator = [ if (res.locals.videoChannel.Actor.isOwned() === false) { return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot update video channel of another server' }) - .end() } if (res.locals.videoChannel.Account.userId !== res.locals.oauth.token.User.id) { return res.status(HttpStatusCode.FORBIDDEN_403) .json({ error: 'Cannot update video channel of another user' }) - .end() } return next() -- cgit v1.2.3