X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fusers.ts;h=d22a745b42a34cce17d151b5c6012651e7c79589;hb=e8e122002d5a6a2bedcf3d66d35657c9b9e1ebaf;hp=7c77e9a3945950a61bd57aca53b75f5f5db3f87d;hpb=47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 7c77e9a39..d22a745b4 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -100,14 +100,22 @@ const usersUpdateMeValidator = [ const usersUpdateMyAvatarValidator = [ body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( 'This file is not supported. Please, make sure it is of the following type : ' - + CONSTRAINTS_FIELDS.ACTOR.AVATAR.EXTNAME.join(', ') + + CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ') ), (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking usersUpdateMyAvatarValidator parameters', { parameters: req.body }) + logger.debug('Checking usersUpdateMyAvatarValidator parameters', { files: req.files }) if (areValidationErrors(req, res)) return + const imageFile = req.files['avatarfile'][0] as Express.Multer.File + if (imageFile.size > CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max) { + res.status(400) + .send({ error: `The size of the avatar is too big (>${CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max}).` }) + .end() + return + } + return next() } ]