2018-06-29 11:29:23 +02:00
|
|
|
import * as express from 'express'
|
2019-07-25 16:23:44 +02:00
|
|
|
import { body } from 'express-validator'
|
2021-04-07 10:36:13 +02:00
|
|
|
import { isActorImageFile } from '@server/helpers/custom-validators/actor-images'
|
2018-08-14 15:28:30 +02:00
|
|
|
import { cleanUpReqFiles } from '../../helpers/express-utils'
|
2021-04-07 10:36:13 +02:00
|
|
|
import { logger } from '../../helpers/logger'
|
|
|
|
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
2021-06-03 17:33:44 +02:00
|
|
|
import { areValidationErrors } from './shared'
|
2018-06-29 11:29:23 +02:00
|
|
|
|
2021-04-06 17:01:35 +02:00
|
|
|
const updateActorImageValidatorFactory = (fieldname: string) => ([
|
2021-04-07 10:36:13 +02:00
|
|
|
body(fieldname).custom((value, { req }) => isActorImageFile(req.files, fieldname)).withMessage(
|
2020-01-31 16:56:52 +01:00
|
|
|
'This file is not supported or too large. Please, make sure it is of the following type : ' +
|
2021-04-06 17:01:35 +02:00
|
|
|
CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME.join(', ')
|
2018-06-29 11:29:23 +02:00
|
|
|
),
|
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2021-04-06 17:01:35 +02:00
|
|
|
logger.debug('Checking updateActorImageValidator parameters', { files: req.files })
|
2018-06-29 11:29:23 +02:00
|
|
|
|
2018-07-31 15:09:34 +02:00
|
|
|
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
|
2018-06-29 11:29:23 +02:00
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
2021-04-06 17:01:35 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
const updateAvatarValidator = updateActorImageValidatorFactory('avatarfile')
|
|
|
|
const updateBannerValidator = updateActorImageValidatorFactory('bannerfile')
|
2018-06-29 11:29:23 +02:00
|
|
|
|
|
|
|
export {
|
2021-04-06 17:01:35 +02:00
|
|
|
updateAvatarValidator,
|
|
|
|
updateBannerValidator
|
2018-06-29 11:29:23 +02:00
|
|
|
}
|