actor-image.ts 1.2 KB

123456789101112131415161718192021222324252627282930
  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 { logger } from '../../helpers/logger'
  6. import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
  7. import { areValidationErrors } from './shared'
  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. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  14. logger.debug('Checking updateActorImageValidator parameters', { files: req.files })
  15. if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
  16. return next()
  17. }
  18. ])
  19. const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile')
  20. const updateBannerValidator = updateActorImageValidatorFactory('bannerfile')
  21. export {
  22. updateAvatarValidator,
  23. updateBannerValidator
  24. }