2021-08-27 08:32:44 -04:00
|
|
|
import express from 'express'
|
2021-06-28 11:30:59 -04:00
|
|
|
import { body, query } from 'express-validator'
|
2021-07-16 04:42:24 -04:00
|
|
|
import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
|
2021-06-28 11:30:59 -04:00
|
|
|
import { isBooleanValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
|
2019-07-23 04:40:39 -04:00
|
|
|
import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
|
2020-08-06 10:14:58 -04:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2021-06-28 11:30:59 -04:00
|
|
|
import { areValidationErrors, doesVideoBlacklistExist, doesVideoExist, isValidVideoIdParam } from '../shared'
|
2017-10-10 04:02:18 -04:00
|
|
|
|
|
|
|
const videosBlacklistRemoveValidator = [
|
2021-06-28 11:30:59 -04:00
|
|
|
isValidVideoIdParam('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
|
2019-08-15 05:53:26 -04:00
|
|
|
if (!await doesVideoBlacklistExist(res.locals.videoAll.id, res)) return
|
2017-11-27 11:30:46 -05:00
|
|
|
|
|
|
|
return next()
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const videosBlacklistAddValidator = [
|
2021-06-28 11:30:59 -04:00
|
|
|
isValidVideoIdParam('videoId'),
|
|
|
|
|
2019-01-10 09:39:51 -05:00
|
|
|
body('unfederate')
|
|
|
|
.optional()
|
2019-07-25 10:23:44 -04:00
|
|
|
.customSanitizer(toBooleanOrNull)
|
2019-01-10 09:39:51 -05:00
|
|
|
.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-08-15 05:53:26 -04:00
|
|
|
const video = res.locals.videoAll
|
2019-01-10 09:39:51 -05:00
|
|
|
if (req.body.unfederate === true && video.remote === true) {
|
2021-05-31 19:36:53 -04:00
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.CONFLICT_409,
|
|
|
|
message: 'You cannot unfederate a remote video.'
|
|
|
|
})
|
2019-01-10 09:39:51 -05:00
|
|
|
}
|
|
|
|
|
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 = [
|
2021-06-28 11:30:59 -04:00
|
|
|
isValidVideoIdParam('videoId'),
|
|
|
|
|
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
|
|
|
|
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
|
2019-08-15 05:53:26 -04:00
|
|
|
if (!await doesVideoBlacklistExist(res.locals.videoAll.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
|
|
|
|
2019-04-02 05:26:47 -04:00
|
|
|
const videosBlacklistFiltersValidator = [
|
|
|
|
query('type')
|
2020-08-06 10:14:58 -04:00
|
|
|
.optional()
|
|
|
|
.customSanitizer(toIntOrNull)
|
2019-04-02 05:26:47 -04:00
|
|
|
.custom(isVideoBlacklistTypeValid).withMessage('Should have a valid video blacklist type attribute'),
|
2020-04-19 08:11:40 -04:00
|
|
|
query('search')
|
|
|
|
.optional()
|
|
|
|
.not()
|
|
|
|
.isEmpty().withMessage('Should have a valid search'),
|
2019-04-02 05:26:47 -04:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking videos blacklist filters query', { parameters: req.query })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
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,
|
2019-04-02 05:26:47 -04:00
|
|
|
videosBlacklistUpdateValidator,
|
|
|
|
videosBlacklistFiltersValidator
|
2017-10-10 04:02:18 -04:00
|
|
|
}
|