diff options
author | Chocobozzz <me@florianbigard.com> | 2021-04-07 10:36:13 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-04-08 10:07:53 +0200 |
commit | 213e30ef90806369529684ac9c247d73b8dc7928 (patch) | |
tree | 7f834f2485a074b1d3052745fa5236d34c0f26db /server/middlewares/validators/actor-image.ts | |
parent | 2cb03dc1f4e01ba491c36caff30c33fe9c5bad89 (diff) | |
download | PeerTube-213e30ef90806369529684ac9c247d73b8dc7928.tar.gz PeerTube-213e30ef90806369529684ac9c247d73b8dc7928.tar.zst PeerTube-213e30ef90806369529684ac9c247d73b8dc7928.zip |
Add banner tests
Diffstat (limited to 'server/middlewares/validators/actor-image.ts')
-rw-r--r-- | server/middlewares/validators/actor-image.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/server/middlewares/validators/actor-image.ts b/server/middlewares/validators/actor-image.ts new file mode 100644 index 000000000..961d7a7e5 --- /dev/null +++ b/server/middlewares/validators/actor-image.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import * as 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 { logger } from '../../helpers/logger' | ||
6 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | ||
7 | import { areValidationErrors } from './utils' | ||
8 | |||
9 | const updateActorImageValidatorFactory = (fieldname: string) => ([ | ||
10 | body(fieldname).custom((value, { req }) => isActorImageFile(req.files, fieldname)).withMessage( | ||
11 | 'This file is not supported or too large. Please, make sure it is of the following type : ' + | ||
12 | CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ') | ||
13 | ), | ||
14 | |||
15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
16 | logger.debug('Checking updateActorImageValidator parameters', { files: req.files }) | ||
17 | |||
18 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) | ||
19 | |||
20 | return next() | ||
21 | } | ||
22 | ]) | ||
23 | |||
24 | const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile') | ||
25 | const updateBannerValidator = updateActorImageValidatorFactory('bannerfile') | ||
26 | |||
27 | export { | ||
28 | updateAvatarValidator, | ||
29 | updateBannerValidator | ||
30 | } | ||