diff options
Diffstat (limited to 'server/middlewares/validators/videos/video-blacklist.ts')
-rw-r--r-- | server/middlewares/validators/videos/video-blacklist.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts new file mode 100644 index 000000000..13da7acff --- /dev/null +++ b/server/middlewares/validators/videos/video-blacklist.ts | |||
@@ -0,0 +1,62 @@ | |||
1 | import * as express from 'express' | ||
2 | import { body, param } from 'express-validator/check' | ||
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' | ||
8 | |||
9 | const videosBlacklistRemoveValidator = [ | ||
10 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | ||
11 | |||
12 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
13 | logger.debug('Checking blacklistRemove parameters.', { parameters: req.params }) | ||
14 | |||
15 | if (areValidationErrors(req, res)) return | ||
16 | if (!await isVideoExist(req.params.videoId, res)) return | ||
17 | if (!await isVideoBlacklistExist(res.locals.video.id, res)) return | ||
18 | |||
19 | return next() | ||
20 | } | ||
21 | ] | ||
22 | |||
23 | const videosBlacklistAddValidator = [ | ||
24 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | ||
25 | body('reason') | ||
26 | .optional() | ||
27 | .custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'), | ||
28 | |||
29 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
30 | logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) | ||
31 | |||
32 | if (areValidationErrors(req, res)) return | ||
33 | if (!await isVideoExist(req.params.videoId, res)) return | ||
34 | |||
35 | return next() | ||
36 | } | ||
37 | ] | ||
38 | |||
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'), | ||
44 | |||
45 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
46 | logger.debug('Checking videosBlacklistUpdate parameters', { parameters: req.params }) | ||
47 | |||
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 | ||
51 | |||
52 | return next() | ||
53 | } | ||
54 | ] | ||
55 | |||
56 | // --------------------------------------------------------------------------- | ||
57 | |||
58 | export { | ||
59 | videosBlacklistAddValidator, | ||
60 | videosBlacklistRemoveValidator, | ||
61 | videosBlacklistUpdateValidator | ||
62 | } | ||