]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/actor-image.ts
Fix filters on playlists
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / actor-image.ts
CommitLineData
41fb13c3 1import express from 'express'
c8861d5d 2import { body } from 'express-validator'
213e30ef 3import { isActorImageFile } from '@server/helpers/custom-validators/actor-images'
06215f15 4import { cleanUpReqFiles } from '../../helpers/express-utils'
213e30ef 5import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
10363c74 6import { areValidationErrors } from './shared'
4bbfc6c6 7
2cb03dc1 8const updateActorImageValidatorFactory = (fieldname: string) => ([
213e30ef 9 body(fieldname).custom((value, { req }) => isActorImageFile(req.files, fieldname)).withMessage(
a1587156 10 'This file is not supported or too large. Please, make sure it is of the following type : ' +
2cb03dc1 11 CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ')
4bbfc6c6
C
12 ),
13
14 (req: express.Request, res: express.Response, next: express.NextFunction) => {
cf7a61b5 15 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
4bbfc6c6
C
16
17 return next()
18 }
2cb03dc1
C
19])
20
21const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile')
22const updateBannerValidator = updateActorImageValidatorFactory('bannerfile')
4bbfc6c6
C
23
24export {
2cb03dc1
C
25 updateAvatarValidator,
26 updateBannerValidator
4bbfc6c6 27}