2017-10-10 03:02:18 -05:00
|
|
|
import * as express from 'express'
|
2018-08-13 09:57:13 -05:00
|
|
|
import { body, param } from 'express-validator/check'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
|
2017-11-27 10:30:46 -06:00
|
|
|
import { isVideoExist } from '../../helpers/custom-validators/videos'
|
2017-12-28 04:16:08 -06:00
|
|
|
import { logger } from '../../helpers/logger'
|
2017-11-27 10:30:46 -06:00
|
|
|
import { areValidationErrors } from './utils'
|
2018-08-13 09:57:13 -05:00
|
|
|
import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist'
|
2017-10-10 03:02:18 -05:00
|
|
|
|
|
|
|
const videosBlacklistRemoveValidator = [
|
2017-10-24 12:41:09 -05:00
|
|
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
2017-10-10 03:02:18 -05:00
|
|
|
|
2017-11-27 10:30:46 -06:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-10-10 03:02:18 -05:00
|
|
|
logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
|
|
|
|
|
2017-11-27 10:30:46 -06:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isVideoExist(req.params.videoId, res)) return
|
2018-08-13 09:57:13 -05:00
|
|
|
if (!await isVideoBlacklistExist(res.locals.video.id, res)) return
|
2017-11-27 10:30:46 -06:00
|
|
|
|
|
|
|
return next()
|
2017-10-10 03:02:18 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const videosBlacklistAddValidator = [
|
2017-10-24 12:41:09 -05:00
|
|
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
2018-08-13 09:57:13 -05:00
|
|
|
body('reason')
|
|
|
|
.optional()
|
|
|
|
.custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
|
2017-10-10 03:02:18 -05:00
|
|
|
|
2017-11-27 10:30:46 -06:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2018-08-13 09:57:13 -05:00
|
|
|
logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params })
|
2017-10-10 03:02:18 -05:00
|
|
|
|
2017-11-27 10:30:46 -06:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isVideoExist(req.params.videoId, res)) return
|
|
|
|
|
|
|
|
return next()
|
2017-10-10 03:02:18 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-08-13 09:57:13 -05:00
|
|
|
const videosBlacklistUpdateValidator = [
|
|
|
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
|
|
|
body('reason')
|
|
|
|
.optional()
|
|
|
|
.custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
|
2017-10-10 03:02:18 -05:00
|
|
|
|
2018-08-13 09:57:13 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params })
|
2017-10-10 03:02:18 -05:00
|
|
|
|
2018-08-13 09:57:13 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isVideoExist(req.params.videoId, res)) return
|
|
|
|
if (!await isVideoBlacklistExist(res.locals.video.id, res)) return
|
2017-11-27 10:30:46 -06:00
|
|
|
|
2018-08-13 09:57:13 -05:00
|
|
|
return next()
|
2017-10-10 03:02:18 -05:00
|
|
|
}
|
2018-08-13 09:57:13 -05:00
|
|
|
]
|
2017-10-10 03:02:18 -05:00
|
|
|
|
2018-08-13 09:57:13 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
2017-10-10 03:02:18 -05:00
|
|
|
|
2018-08-13 09:57:13 -05:00
|
|
|
export {
|
|
|
|
videosBlacklistAddValidator,
|
|
|
|
videosBlacklistRemoveValidator,
|
|
|
|
videosBlacklistUpdateValidator
|
2017-10-10 03:02:18 -05:00
|
|
|
}
|