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