-import * as express from 'express'
-import { body, param, query } from 'express-validator'
-import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
-import { logger } from '../../../helpers/logger'
-import { areValidationErrors } from '../utils'
+import express from 'express'
+import { body, query } from 'express-validator'
+import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
+import { isBooleanValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
-import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares'
+import { logger } from '../../../helpers/logger'
+import { areValidationErrors, doesVideoBlacklistExist, doesVideoExist, isValidVideoIdParam } from '../shared'
const videosBlacklistRemoveValidator = [
- param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
+ isValidVideoIdParam('videoId'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
]
const videosBlacklistAddValidator = [
- param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
+ isValidVideoIdParam('videoId'),
+
body('unfederate')
.optional()
.customSanitizer(toBooleanOrNull)
const video = res.locals.videoAll
if (req.body.unfederate === true && video.remote === true) {
- return res
- .status(409)
- .send({ error: 'You cannot unfederate a remote video.' })
- .end()
+ return res.fail({
+ status: HttpStatusCode.CONFLICT_409,
+ message: 'You cannot unfederate a remote video.'
+ })
}
return next()
]
const videosBlacklistUpdateValidator = [
- param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
+ isValidVideoIdParam('videoId'),
+
body('reason')
.optional()
.custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
const videosBlacklistFiltersValidator = [
query('type')
- .optional()
+ .optional()
+ .customSanitizer(toIntOrNull)
.custom(isVideoBlacklistTypeValid).withMessage('Should have a valid video blacklist type attribute'),
+ query('search')
+ .optional()
+ .not()
+ .isEmpty().withMessage('Should have a valid search'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videos blacklist filters query', { parameters: req.query })