diff options
Diffstat (limited to 'server/middlewares/validators/search.ts')
-rw-r--r-- | server/middlewares/validators/search.ts | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 7bbf81048..27d0e541d 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts | |||
@@ -1,13 +1,18 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' | 3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | 4 | import { isHostValid } from '@server/helpers/custom-validators/servers' |
5 | import { areUUIDsValid, isDateValid, isNotEmptyStringArray, toCompleteUUIDs } from '../../helpers/custom-validators/misc' | ||
5 | import { logger } from '../../helpers/logger' | 6 | import { logger } from '../../helpers/logger' |
6 | import { areValidationErrors } from './shared' | 7 | import { areValidationErrors } from './shared' |
7 | 8 | ||
8 | const videosSearchValidator = [ | 9 | const videosSearchValidator = [ |
9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | 10 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), |
10 | 11 | ||
12 | query('host') | ||
13 | .optional() | ||
14 | .custom(isHostValid).withMessage('Should have a valid host'), | ||
15 | |||
11 | query('startDate') | 16 | query('startDate') |
12 | .optional() | 17 | .optional() |
13 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | 18 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), |
@@ -22,8 +27,18 @@ const videosSearchValidator = [ | |||
22 | .optional() | 27 | .optional() |
23 | .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), | 28 | .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), |
24 | 29 | ||
25 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), | 30 | query('durationMin') |
26 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), | 31 | .optional() |
32 | .isInt().withMessage('Should have a valid min duration'), | ||
33 | query('durationMax') | ||
34 | .optional() | ||
35 | .isInt().withMessage('Should have a valid max duration'), | ||
36 | |||
37 | query('uuids') | ||
38 | .optional() | ||
39 | .toArray() | ||
40 | .customSanitizer(toCompleteUUIDs) | ||
41 | .custom(areUUIDsValid).withMessage('Should have valid uuids'), | ||
27 | 42 | ||
28 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | 43 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
29 | 44 | ||
@@ -37,8 +52,22 @@ const videosSearchValidator = [ | |||
37 | ] | 52 | ] |
38 | 53 | ||
39 | const videoChannelsListSearchValidator = [ | 54 | const videoChannelsListSearchValidator = [ |
40 | query('search').not().isEmpty().withMessage('Should have a valid search'), | 55 | query('search') |
41 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | 56 | .optional() |
57 | .not().isEmpty().withMessage('Should have a valid search'), | ||
58 | |||
59 | query('host') | ||
60 | .optional() | ||
61 | .custom(isHostValid).withMessage('Should have a valid host'), | ||
62 | |||
63 | query('searchTarget') | ||
64 | .optional() | ||
65 | .custom(isSearchTargetValid).withMessage('Should have a valid search target'), | ||
66 | |||
67 | query('handles') | ||
68 | .optional() | ||
69 | .toArray() | ||
70 | .custom(isNotEmptyStringArray).withMessage('Should have valid handles'), | ||
42 | 71 | ||
43 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 72 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
44 | logger.debug('Checking video channels search query', { parameters: req.query }) | 73 | logger.debug('Checking video channels search query', { parameters: req.query }) |
@@ -50,8 +79,23 @@ const videoChannelsListSearchValidator = [ | |||
50 | ] | 79 | ] |
51 | 80 | ||
52 | const videoPlaylistsListSearchValidator = [ | 81 | const videoPlaylistsListSearchValidator = [ |
53 | query('search').not().isEmpty().withMessage('Should have a valid search'), | 82 | query('search') |
54 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | 83 | .optional() |
84 | .not().isEmpty().withMessage('Should have a valid search'), | ||
85 | |||
86 | query('host') | ||
87 | .optional() | ||
88 | .custom(isHostValid).withMessage('Should have a valid host'), | ||
89 | |||
90 | query('searchTarget') | ||
91 | .optional() | ||
92 | .custom(isSearchTargetValid).withMessage('Should have a valid search target'), | ||
93 | |||
94 | query('uuids') | ||
95 | .optional() | ||
96 | .toArray() | ||
97 | .customSanitizer(toCompleteUUIDs) | ||
98 | .custom(areUUIDsValid).withMessage('Should have valid uuids'), | ||
55 | 99 | ||
56 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 100 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
57 | logger.debug('Checking video playlists search query', { parameters: req.query }) | 101 | logger.debug('Checking video playlists search query', { parameters: req.query }) |