]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/search.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / search.ts
CommitLineData
57c36b27
C
1import * as express from 'express'
2import { areValidationErrors } from './utils'
3import { logger } from '../../helpers/logger'
c8861d5d 4import { query } from 'express-validator'
1cd3facc 5import { isDateValid } from '../../helpers/custom-validators/misc'
3b0bd70a 6import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
57c36b27 7
f37dc0dd 8const videosSearchValidator = [
d4112450 9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
57c36b27 10
d525fc39
C
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
c74c9be9
C
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
d525fc39
C
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
3b0bd70a
C
20 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
21
d525fc39 22 (req: express.Request, res: express.Response, next: express.NextFunction) => {
f37dc0dd
C
23 logger.debug('Checking videos search query', { parameters: req.query })
24
25 if (areValidationErrors(req, res)) return
26
27 return next()
28 }
29]
30
7b390964 31const videoChannelsListSearchValidator = [
f37dc0dd 32 query('search').not().isEmpty().withMessage('Should have a valid search'),
3b0bd70a 33 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
f37dc0dd
C
34
35 (req: express.Request, res: express.Response, next: express.NextFunction) => {
36 logger.debug('Checking video channels search query', { parameters: req.query })
d525fc39
C
37
38 if (areValidationErrors(req, res)) return
39
40 return next()
41 }
42]
43
bc99dfe5
RK
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
57c36b27
C
56// ---------------------------------------------------------------------------
57
58export {
bc99dfe5 59 videosSearchValidator,
7b390964 60 videoChannelsListSearchValidator,
bc99dfe5 61 videoChannelsOwnSearchValidator
57c36b27 62}