1
0
Fork 0
peertube/server/middlewares/validators/avatar.ts

27 lines
938 B
TypeScript
Raw Normal View History

import * as express from 'express'
2019-07-25 14:23:44 +00:00
import { body } from 'express-validator'
import { isAvatarFile } from '../../helpers/custom-validators/users'
import { areValidationErrors } from './utils'
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { logger } from '../../helpers/logger'
2018-08-14 13:28:30 +00:00
import { cleanUpReqFiles } from '../../helpers/express-utils'
const updateAvatarValidator = [
body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).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 : ' +
CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ')
),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking updateAvatarValidator parameters', { files: req.files })
2018-07-31 13:09:34 +00:00
if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
return next()
}
]
export {
updateAvatarValidator
}