]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { body } from 'express-validator' |
213e30ef | 3 | import { isActorImageFile } from '@server/helpers/custom-validators/actor-images' |
06215f15 | 4 | import { cleanUpReqFiles } from '../../helpers/express-utils' |
213e30ef | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
10363c74 | 6 | import { areValidationErrors } from './shared' |
4bbfc6c6 | 7 | |
2cb03dc1 | 8 | const 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 | ||
21 | const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile') | |
22 | const updateBannerValidator = updateActorImageValidatorFactory('bannerfile') | |
4bbfc6c6 C |
23 | |
24 | export { | |
2cb03dc1 C |
25 | updateAvatarValidator, |
26 | updateBannerValidator | |
4bbfc6c6 | 27 | } |