]>
Commit | Line | Data |
---|---|---|
57c36b27 | 1 | import * as express from 'express' |
c8861d5d | 2 | import { query } from 'express-validator' |
3b0bd70a | 3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
29837f88 | 4 | import { isHostValid } from '@server/helpers/custom-validators/servers' |
10363c74 C |
5 | import { isDateValid } from '../../helpers/custom-validators/misc' |
6 | import { logger } from '../../helpers/logger' | |
7 | import { areValidationErrors } from './shared' | |
57c36b27 | 8 | |
f37dc0dd | 9 | const videosSearchValidator = [ |
d4112450 | 10 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), |
57c36b27 | 11 | |
29837f88 C |
12 | query('host') |
13 | .optional() | |
14 | .custom(isHostValid).withMessage('Should have a valid host'), | |
15 | ||
70330f63 RK |
16 | query('startDate') |
17 | .optional() | |
18 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | |
19 | query('endDate') | |
20 | .optional() | |
21 | .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'), | |
22 | ||
23 | query('originallyPublishedStartDate') | |
24 | .optional() | |
25 | .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'), | |
26 | query('originallyPublishedEndDate') | |
27 | .optional() | |
28 | .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), | |
c74c9be9 | 29 | |
d525fc39 C |
30 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), |
31 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), | |
32 | ||
3b0bd70a C |
33 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
34 | ||
d525fc39 | 35 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
f37dc0dd C |
36 | logger.debug('Checking videos search query', { parameters: req.query }) |
37 | ||
38 | if (areValidationErrors(req, res)) return | |
39 | ||
40 | return next() | |
41 | } | |
42 | ] | |
43 | ||
7b390964 | 44 | const videoChannelsListSearchValidator = [ |
f37dc0dd | 45 | query('search').not().isEmpty().withMessage('Should have a valid search'), |
fa47956e C |
46 | |
47 | query('host') | |
48 | .optional() | |
49 | .custom(isHostValid).withMessage('Should have a valid host'), | |
50 | ||
51 | query('searchTarget') | |
52 | .optional() | |
53 | .custom(isSearchTargetValid).withMessage('Should have a valid search target'), | |
f37dc0dd C |
54 | |
55 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
56 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
d525fc39 C |
57 | |
58 | if (areValidationErrors(req, res)) return | |
59 | ||
60 | return next() | |
61 | } | |
62 | ] | |
63 | ||
37a44fc9 C |
64 | const videoPlaylistsListSearchValidator = [ |
65 | query('search').not().isEmpty().withMessage('Should have a valid search'), | |
fa47956e C |
66 | |
67 | query('host') | |
68 | .optional() | |
69 | .custom(isHostValid).withMessage('Should have a valid host'), | |
70 | ||
71 | query('searchTarget') | |
72 | .optional() | |
73 | .custom(isSearchTargetValid).withMessage('Should have a valid search target'), | |
bc99dfe5 RK |
74 | |
75 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
37a44fc9 | 76 | logger.debug('Checking video playlists search query', { parameters: req.query }) |
bc99dfe5 RK |
77 | |
78 | if (areValidationErrors(req, res)) return | |
79 | ||
80 | return next() | |
81 | } | |
82 | ] | |
83 | ||
57c36b27 C |
84 | // --------------------------------------------------------------------------- |
85 | ||
86 | export { | |
bc99dfe5 | 87 | videosSearchValidator, |
7b390964 | 88 | videoChannelsListSearchValidator, |
37a44fc9 | 89 | videoPlaylistsListSearchValidator |
57c36b27 | 90 | } |