]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/users.ts
Automatically resize avatars
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / users.ts
index 7c77e9a3945950a61bd57aca53b75f5f5db3f87d..d22a745b42a34cce17d151b5c6012651e7c79589 100644 (file)
@@ -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()
   }
 ]