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