]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import 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' |
b033851f | 5 | import { areUUIDsValid, isDateValid, isNotEmptyStringArray, toCompleteUUIDs } from '../../helpers/custom-validators/misc' |
10363c74 C |
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 | |
fbd67e7f C |
30 | query('durationMin') |
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'), | |
d525fc39 | 42 | |
3b0bd70a C |
43 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
44 | ||
d525fc39 | 45 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
f37dc0dd C |
46 | logger.debug('Checking videos search query', { parameters: req.query }) |
47 | ||
48 | if (areValidationErrors(req, res)) return | |
49 | ||
50 | return next() | |
51 | } | |
52 | ] | |
53 | ||
7b390964 | 54 | const videoChannelsListSearchValidator = [ |
fbd67e7f C |
55 | query('search') |
56 | .optional() | |
57 | .not().isEmpty().withMessage('Should have a valid search'), | |
fa47956e C |
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'), | |
f37dc0dd | 66 | |
b033851f | 67 | query('handles') |
fbd67e7f | 68 | .optional() |
b033851f C |
69 | .toArray() |
70 | .custom(isNotEmptyStringArray).withMessage('Should have valid handles'), | |
fbd67e7f | 71 | |
f37dc0dd C |
72 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
73 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
d525fc39 C |
74 | |
75 | if (areValidationErrors(req, res)) return | |
76 | ||
77 | return next() | |
78 | } | |
79 | ] | |
80 | ||
37a44fc9 | 81 | const videoPlaylistsListSearchValidator = [ |
fbd67e7f C |
82 | query('search') |
83 | .optional() | |
84 | .not().isEmpty().withMessage('Should have a valid search'), | |
fa47956e C |
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'), | |
bc99dfe5 | 93 | |
fbd67e7f C |
94 | query('uuids') |
95 | .optional() | |
96 | .toArray() | |
97 | .customSanitizer(toCompleteUUIDs) | |
98 | .custom(areUUIDsValid).withMessage('Should have valid uuids'), | |
99 | ||
bc99dfe5 | 100 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
37a44fc9 | 101 | logger.debug('Checking video playlists search query', { parameters: req.query }) |
bc99dfe5 RK |
102 | |
103 | if (areValidationErrors(req, res)) return | |
104 | ||
105 | return next() | |
106 | } | |
107 | ] | |
108 | ||
57c36b27 C |
109 | // --------------------------------------------------------------------------- |
110 | ||
111 | export { | |
bc99dfe5 | 112 | videosSearchValidator, |
7b390964 | 113 | videoChannelsListSearchValidator, |
37a44fc9 | 114 | videoPlaylistsListSearchValidator |
57c36b27 | 115 | } |