]>
Commit | Line | Data |
---|---|---|
35bf0c83 | 1 | import * as express from 'express' |
26b7305a | 2 | import { body, param } from 'express-validator/check' |
6e46de09 C |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
4 | import { isVideoExist } from '../../../helpers/custom-validators/videos' | |
5 | import { logger } from '../../../helpers/logger' | |
6 | import { areValidationErrors } from '../utils' | |
7 | import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist' | |
35bf0c83 C |
8 | |
9 | const videosBlacklistRemoveValidator = [ | |
72c7248b | 10 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
35bf0c83 | 11 | |
a2431b7d | 12 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
35bf0c83 C |
13 | logger.debug('Checking blacklistRemove parameters.', { parameters: req.params }) |
14 | ||
a2431b7d C |
15 | if (areValidationErrors(req, res)) return |
16 | if (!await isVideoExist(req.params.videoId, res)) return | |
26b7305a | 17 | if (!await isVideoBlacklistExist(res.locals.video.id, res)) return |
a2431b7d C |
18 | |
19 | return next() | |
35bf0c83 C |
20 | } |
21 | ] | |
22 | ||
23 | const videosBlacklistAddValidator = [ | |
72c7248b | 24 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), |
26b7305a C |
25 | body('reason') |
26 | .optional() | |
27 | .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'), | |
35bf0c83 | 28 | |
a2431b7d | 29 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
26b7305a | 30 | logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) |
35bf0c83 | 31 | |
a2431b7d C |
32 | if (areValidationErrors(req, res)) return |
33 | if (!await isVideoExist(req.params.videoId, res)) return | |
a2431b7d C |
34 | |
35 | return next() | |
35bf0c83 C |
36 | } |
37 | ] | |
38 | ||
26b7305a C |
39 | const videosBlacklistUpdateValidator = [ |
40 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | |
41 | body('reason') | |
42 | .optional() | |
43 | .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'), | |
35bf0c83 | 44 | |
26b7305a C |
45 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
46 | logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params }) | |
35bf0c83 | 47 | |
26b7305a C |
48 | if (areValidationErrors(req, res)) return |
49 | if (!await isVideoExist(req.params.videoId, res)) return | |
50 | if (!await isVideoBlacklistExist(res.locals.video.id, res)) return | |
a2431b7d | 51 | |
26b7305a | 52 | return next() |
35bf0c83 | 53 | } |
26b7305a | 54 | ] |
35bf0c83 | 55 | |
26b7305a | 56 | // --------------------------------------------------------------------------- |
35bf0c83 | 57 | |
26b7305a C |
58 | export { |
59 | videosBlacklistAddValidator, | |
60 | videosBlacklistRemoveValidator, | |
61 | videosBlacklistUpdateValidator | |
35bf0c83 | 62 | } |