]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/search.ts
Add server plugin filter hooks for import with torrent and url (#2621)
[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'
57c36b27 6
f37dc0dd 7const videosSearchValidator = [
d4112450 8 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
57c36b27 9
d525fc39
C
10 query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
11 query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),
12
c74c9be9
C
13 query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'),
14 query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'),
15
d525fc39
C
16 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
17 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
18
19 (req: express.Request, res: express.Response, next: express.NextFunction) => {
f37dc0dd
C
20 logger.debug('Checking videos search query', { parameters: req.query })
21
22 if (areValidationErrors(req, res)) return
23
24 return next()
25 }
26]
27
28const videoChannelsSearchValidator = [
29 query('search').not().isEmpty().withMessage('Should have a valid search'),
30
31 (req: express.Request, res: express.Response, next: express.NextFunction) => {
32 logger.debug('Checking video channels search query', { parameters: req.query })
d525fc39
C
33
34 if (areValidationErrors(req, res)) return
35
36 return next()
37 }
38]
39
57c36b27
C
40// ---------------------------------------------------------------------------
41
42export {
f37dc0dd
C
43 videoChannelsSearchValidator,
44 videosSearchValidator
57c36b27 45}