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