1
0
Fork 0
peertube/server/middlewares/validators/actor-image.ts

28 lines
1.0 KiB
TypeScript
Raw Normal View History

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