mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add avatar max size limit
This commit is contained in:
parent
47564bbe2e
commit
01de67b9a4
17 changed files with 226 additions and 30 deletions
|
@ -12,6 +12,7 @@ import { isSignupAllowed } from '../../helpers/utils'
|
|||
import { CONSTRAINTS_FIELDS } from '../../initializers'
|
||||
import { UserModel } from '../../models/account/user'
|
||||
import { areValidationErrors } from './utils'
|
||||
import Multer = require('multer')
|
||||
|
||||
const usersAddValidator = [
|
||||
body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
|
||||
|
@ -100,7 +101,7 @@ 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) => {
|
||||
|
@ -108,6 +109,14 @@ const usersUpdateMyAvatarValidator = [
|
|||
|
||||
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()
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue