2017-10-10 04:02:18 -04:00
|
|
|
import * as express from 'express'
|
2018-08-13 10:57:13 -04:00
|
|
|
import { body, param } from 'express-validator/check'
|
2019-01-10 09:39:51 -05:00
|
|
|
import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
|
2019-03-19 04:26:50 -04:00
|
|
|
import { doesVideoExist } from '../../../helpers/custom-validators/videos'
|
2018-10-05 05:15:06 -04:00
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { areValidationErrors } from '../utils'
|
2019-03-19 04:26:50 -04:00
|
|
|
import { doesVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'
|
2019-01-10 09:39:51 -05:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2017-10-10 04:02:18 -04:00
|
|
|
|
|
|
|
const videosBlacklistRemoveValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-10-10 04:02:18 -04:00
|
|
|
logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
|
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.videoId, res)) return
|
|
|
|
if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
return next()
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const videosBlacklistAddValidator = [
|
2017-10-24 13:41:09 -04:00
|
|
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
2019-01-10 09:39:51 -05:00
|
|
|
body('unfederate')
|
|
|
|
.optional()
|
|
|
|
.toBoolean()
|
|
|
|
.custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
|
2018-08-13 10:57:13 -04:00
|
|
|
body('reason')
|
|
|
|
.optional()
|
|
|
|
.custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2018-08-13 10:57:13 -04:00
|
|
|
logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params })
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.videoId, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
2019-01-10 09:39:51 -05:00
|
|
|
const video: VideoModel = res.locals.video
|
|
|
|
if (req.body.unfederate === true && video.remote === true) {
|
|
|
|
return res
|
|
|
|
.status(409)
|
|
|
|
.send({ error: 'You cannot unfederate a remote video.' })
|
|
|
|
.end()
|
|
|
|
}
|
|
|
|
|
2017-11-27 11:30:46 -05:00
|
|
|
return next()
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-08-13 10:57:13 -04: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 04:02:18 -04:00
|
|
|
|
2018-08-13 10:57:13 -04:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params })
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2018-08-13 10:57:13 -04:00
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.videoId, res)) return
|
|
|
|
if (!await doesVideoBlacklistExist(res.locals.video.id, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
2018-08-13 10:57:13 -04:00
|
|
|
return next()
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|
2018-08-13 10:57:13 -04:00
|
|
|
]
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2018-08-13 10:57:13 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
2017-10-10 04:02:18 -04:00
|
|
|
|
2018-08-13 10:57:13 -04:00
|
|
|
export {
|
|
|
|
videosBlacklistAddValidator,
|
|
|
|
videosBlacklistRemoveValidator,
|
|
|
|
videosBlacklistUpdateValidator
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|