diff options
Diffstat (limited to 'server/middlewares/validators/avatar.ts')
-rw-r--r-- | server/middlewares/validators/avatar.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.ts index 2acb97483..f7eb367bd 100644 --- a/server/middlewares/validators/avatar.ts +++ b/server/middlewares/validators/avatar.ts | |||
@@ -6,21 +6,25 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | |||
6 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
7 | import { cleanUpReqFiles } from '../../helpers/express-utils' | 7 | import { cleanUpReqFiles } from '../../helpers/express-utils' |
8 | 8 | ||
9 | const updateAvatarValidator = [ | 9 | const updateActorImageValidatorFactory = (fieldname: string) => ([ |
10 | body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( | 10 | body(fieldname).custom((value, { req }) => isAvatarFile(req.files)).withMessage( |
11 | 'This file is not supported or too large. Please, make sure it is of the following type : ' + | 11 | 'This file is not supported or too large. Please, make sure it is of the following type : ' + |
12 | CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ') | 12 | CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ') |
13 | ), | 13 | ), |
14 | 14 | ||
15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
16 | logger.debug('Checking updateAvatarValidator parameters', { files: req.files }) | 16 | logger.debug('Checking updateActorImageValidator parameters', { files: req.files }) |
17 | 17 | ||
18 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) | 18 | if (areValidationErrors(req, res)) return cleanUpReqFiles(req) |
19 | 19 | ||
20 | return next() | 20 | return next() |
21 | } | 21 | } |
22 | ] | 22 | ]) |
23 | |||
24 | const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile') | ||
25 | const updateBannerValidator = updateActorImageValidatorFactory('bannerfile') | ||
23 | 26 | ||
24 | export { | 27 | export { |
25 | updateAvatarValidator | 28 | updateAvatarValidator, |
29 | updateBannerValidator | ||
26 | } | 30 | } |