avatar.ts 944 B

1234567891011121314151617181920212223242526
  1. import * as express from 'express'
  2. import { body } from 'express-validator/check'
  3. import { isAvatarFile } from '../../helpers/custom-validators/users'
  4. import { areValidationErrors } from './utils'
  5. import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
  6. import { logger } from '../../helpers/logger'
  7. import { cleanUpReqFiles } from '../../helpers/express-utils'
  8. const updateAvatarValidator = [
  9. body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage(
  10. 'This file is not supported or too large. Please, make sure it is of the following type : '
  11. + CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ')
  12. ),
  13. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  14. logger.debug('Checking updateAvatarValidator parameters', { files: req.files })
  15. if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
  16. return next()
  17. }
  18. ]
  19. export {
  20. updateAvatarValidator
  21. }