]>
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 = [ |
396f6f01 C |
10 | query('search') |
11 | .optional() | |
12 | .not().isEmpty(), | |
57c36b27 | 13 | |
29837f88 C |
14 | query('host') |
15 | .optional() | |
396f6f01 | 16 | .custom(isHostValid), |
29837f88 | 17 | |
70330f63 RK |
18 | query('startDate') |
19 | .optional() | |
20 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | |
21 | query('endDate') | |
22 | .optional() | |
23 | .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'), | |
24 | ||
25 | query('originallyPublishedStartDate') | |
26 | .optional() | |
27 | .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'), | |
28 | query('originallyPublishedEndDate') | |
29 | .optional() | |
30 | .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), | |
c74c9be9 | 31 | |
fbd67e7f C |
32 | query('durationMin') |
33 | .optional() | |
396f6f01 | 34 | .isInt(), |
fbd67e7f C |
35 | query('durationMax') |
36 | .optional() | |
396f6f01 | 37 | .isInt(), |
fbd67e7f C |
38 | |
39 | query('uuids') | |
40 | .optional() | |
41 | .toArray() | |
42 | .customSanitizer(toCompleteUUIDs) | |
396f6f01 | 43 | .custom(areUUIDsValid).withMessage('Should have valid array of uuid'), |
d525fc39 | 44 | |
396f6f01 C |
45 | query('searchTarget') |
46 | .optional() | |
47 | .custom(isSearchTargetValid), | |
3b0bd70a | 48 | |
d525fc39 | 49 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
f37dc0dd C |
50 | logger.debug('Checking videos search query', { parameters: req.query }) |
51 | ||
52 | if (areValidationErrors(req, res)) return | |
53 | ||
54 | return next() | |
55 | } | |
56 | ] | |
57 | ||
7b390964 | 58 | const videoChannelsListSearchValidator = [ |
fbd67e7f C |
59 | query('search') |
60 | .optional() | |
396f6f01 | 61 | .not().isEmpty(), |
fa47956e C |
62 | |
63 | query('host') | |
64 | .optional() | |
396f6f01 | 65 | .custom(isHostValid), |
fa47956e C |
66 | |
67 | query('searchTarget') | |
68 | .optional() | |
396f6f01 | 69 | .custom(isSearchTargetValid), |
f37dc0dd | 70 | |
b033851f | 71 | query('handles') |
fbd67e7f | 72 | .optional() |
b033851f | 73 | .toArray() |
396f6f01 | 74 | .custom(isNotEmptyStringArray).withMessage('Should have valid array of handles'), |
fbd67e7f | 75 | |
f37dc0dd C |
76 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
77 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
d525fc39 C |
78 | |
79 | if (areValidationErrors(req, res)) return | |
80 | ||
81 | return next() | |
82 | } | |
83 | ] | |
84 | ||
37a44fc9 | 85 | const videoPlaylistsListSearchValidator = [ |
fbd67e7f C |
86 | query('search') |
87 | .optional() | |
396f6f01 | 88 | .not().isEmpty(), |
fa47956e C |
89 | |
90 | query('host') | |
91 | .optional() | |
396f6f01 | 92 | .custom(isHostValid), |
fa47956e C |
93 | |
94 | query('searchTarget') | |
95 | .optional() | |
396f6f01 | 96 | .custom(isSearchTargetValid), |
bc99dfe5 | 97 | |
fbd67e7f C |
98 | query('uuids') |
99 | .optional() | |
100 | .toArray() | |
101 | .customSanitizer(toCompleteUUIDs) | |
396f6f01 | 102 | .custom(areUUIDsValid).withMessage('Should have valid array of uuid'), |
fbd67e7f | 103 | |
bc99dfe5 | 104 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
37a44fc9 | 105 | logger.debug('Checking video playlists search query', { parameters: req.query }) |
bc99dfe5 RK |
106 | |
107 | if (areValidationErrors(req, res)) return | |
108 | ||
109 | return next() | |
110 | } | |
111 | ] | |
112 | ||
57c36b27 C |
113 | // --------------------------------------------------------------------------- |
114 | ||
115 | export { | |
bc99dfe5 | 116 | videosSearchValidator, |
7b390964 | 117 | videoChannelsListSearchValidator, |
37a44fc9 | 118 | videoPlaylistsListSearchValidator |
57c36b27 | 119 | } |