]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/avatar.ts
Add banners support
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / avatar.ts
CommitLineData
4bbfc6c6 1import * as express from 'express'
c8861d5d 2import { body } from 'express-validator'
4bbfc6c6
C
3import { isAvatarFile } from '../../helpers/custom-validators/users'
4import { areValidationErrors } from './utils'
74dc3bca 5import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
4bbfc6c6 6import { logger } from '../../helpers/logger'
06215f15 7import { cleanUpReqFiles } from '../../helpers/express-utils'
4bbfc6c6 8
2cb03dc1
C
9const updateActorImageValidatorFactory = (fieldname: string) => ([
10 body(fieldname).custom((value, { req }) => isAvatarFile(req.files)).withMessage(
a1587156 11 'This file is not supported or too large. Please, make sure it is of the following type : ' +
2cb03dc1 12 CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ')
4bbfc6c6
C
13 ),
14
15 (req: express.Request, res: express.Response, next: express.NextFunction) => {
2cb03dc1 16 logger.debug('Checking updateActorImageValidator parameters', { files: req.files })
4bbfc6c6 17
cf7a61b5 18 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
4bbfc6c6
C
19
20 return next()
21 }
2cb03dc1
C
22])
23
24const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile')
25const updateBannerValidator = updateActorImageValidatorFactory('bannerfile')
4bbfc6c6
C
26
27export {
2cb03dc1
C
28 updateAvatarValidator,
29 updateBannerValidator
4bbfc6c6 30}