]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/search.ts
Cleanup useless express validator messages
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / search.ts
1 import express from 'express'
2 import { query } from 'express-validator'
3 import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
4 import { isHostValid } from '@server/helpers/custom-validators/servers'
5 import { areUUIDsValid, isDateValid, isNotEmptyStringArray, toCompleteUUIDs } from '../../helpers/custom-validators/misc'
6 import { logger } from '../../helpers/logger'
7 import { areValidationErrors } from './shared'
8
9 const videosSearchValidator = [
10 query('search')
11 .optional()
12 .not().isEmpty(),
13
14 query('host')
15 .optional()
16 .custom(isHostValid),
17
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'),
31
32 query('durationMin')
33 .optional()
34 .isInt(),
35 query('durationMax')
36 .optional()
37 .isInt(),
38
39 query('uuids')
40 .optional()
41 .toArray()
42 .customSanitizer(toCompleteUUIDs)
43 .custom(areUUIDsValid).withMessage('Should have valid array of uuid'),
44
45 query('searchTarget')
46 .optional()
47 .custom(isSearchTargetValid),
48
49 (req: express.Request, res: express.Response, next: express.NextFunction) => {
50 logger.debug('Checking videos search query', { parameters: req.query })
51
52 if (areValidationErrors(req, res)) return
53
54 return next()
55 }
56 ]
57
58 const videoChannelsListSearchValidator = [
59 query('search')
60 .optional()
61 .not().isEmpty(),
62
63 query('host')
64 .optional()
65 .custom(isHostValid),
66
67 query('searchTarget')
68 .optional()
69 .custom(isSearchTargetValid),
70
71 query('handles')
72 .optional()
73 .toArray()
74 .custom(isNotEmptyStringArray).withMessage('Should have valid array of handles'),
75
76 (req: express.Request, res: express.Response, next: express.NextFunction) => {
77 logger.debug('Checking video channels search query', { parameters: req.query })
78
79 if (areValidationErrors(req, res)) return
80
81 return next()
82 }
83 ]
84
85 const videoPlaylistsListSearchValidator = [
86 query('search')
87 .optional()
88 .not().isEmpty(),
89
90 query('host')
91 .optional()
92 .custom(isHostValid),
93
94 query('searchTarget')
95 .optional()
96 .custom(isSearchTargetValid),
97
98 query('uuids')
99 .optional()
100 .toArray()
101 .customSanitizer(toCompleteUUIDs)
102 .custom(areUUIDsValid).withMessage('Should have valid array of uuid'),
103
104 (req: express.Request, res: express.Response, next: express.NextFunction) => {
105 logger.debug('Checking video playlists search query', { parameters: req.query })
106
107 if (areValidationErrors(req, res)) return
108
109 return next()
110 }
111 ]
112
113 // ---------------------------------------------------------------------------
114
115 export {
116 videosSearchValidator,
117 videoChannelsListSearchValidator,
118 videoPlaylistsListSearchValidator
119 }