]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/search.ts
Support short uuid for GET video/playlist
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / search.ts
1 import * as express from 'express'
2 import { query } from 'express-validator'
3 import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
4 import { isDateValid } from '../../helpers/custom-validators/misc'
5 import { logger } from '../../helpers/logger'
6 import { areValidationErrors } from './shared'
7
8 const videosSearchValidator = [
9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
10
11 query('startDate')
12 .optional()
13 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
14 query('endDate')
15 .optional()
16 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
17
18 query('originallyPublishedStartDate')
19 .optional()
20 .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'),
21 query('originallyPublishedEndDate')
22 .optional()
23 .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'),
24
25 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
26 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
27
28 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
29
30 (req: express.Request, res: express.Response, next: express.NextFunction) => {
31 logger.debug('Checking videos search query', { parameters: req.query })
32
33 if (areValidationErrors(req, res)) return
34
35 return next()
36 }
37 ]
38
39 const videoChannelsListSearchValidator = [
40 query('search').not().isEmpty().withMessage('Should have a valid search'),
41 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
42
43 (req: express.Request, res: express.Response, next: express.NextFunction) => {
44 logger.debug('Checking video channels search query', { parameters: req.query })
45
46 if (areValidationErrors(req, res)) return
47
48 return next()
49 }
50 ]
51
52 const videoPlaylistsListSearchValidator = [
53 query('search').not().isEmpty().withMessage('Should have a valid search'),
54 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
55
56 (req: express.Request, res: express.Response, next: express.NextFunction) => {
57 logger.debug('Checking video playlists search query', { parameters: req.query })
58
59 if (areValidationErrors(req, res)) return
60
61 return next()
62 }
63 ]
64
65 // ---------------------------------------------------------------------------
66
67 export {
68 videosSearchValidator,
69 videoChannelsListSearchValidator,
70 videoPlaylistsListSearchValidator
71 }