]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/search.ts
add video upload types, add doc middleware to more routes
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / search.ts
CommitLineData
57c36b27 1import * as express from 'express'
c8861d5d 2import { query } from 'express-validator'
3b0bd70a 3import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
10363c74
C
4import { isDateValid } from '../../helpers/custom-validators/misc'
5import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './shared'
57c36b27 7
f37dc0dd 8const videosSearchValidator = [
d4112450 9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
57c36b27 10
70330f63
RK
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'),
c74c9be9 24
d525fc39
C
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
3b0bd70a
C
28 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
29
d525fc39 30 (req: express.Request, res: express.Response, next: express.NextFunction) => {
f37dc0dd
C
31 logger.debug('Checking videos search query', { parameters: req.query })
32
33 if (areValidationErrors(req, res)) return
34
35 return next()
36 }
37]
38
7b390964 39const videoChannelsListSearchValidator = [
f37dc0dd 40 query('search').not().isEmpty().withMessage('Should have a valid search'),
3b0bd70a 41 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
f37dc0dd
C
42
43 (req: express.Request, res: express.Response, next: express.NextFunction) => {
44 logger.debug('Checking video channels search query', { parameters: req.query })
d525fc39
C
45
46 if (areValidationErrors(req, res)) return
47
48 return next()
49 }
50]
51
bc99dfe5
RK
52const videoChannelsOwnSearchValidator = [
53 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
54
55 (req: express.Request, res: express.Response, next: express.NextFunction) => {
56 logger.debug('Checking video channels search query', { parameters: req.query })
57
58 if (areValidationErrors(req, res)) return
59
60 return next()
61 }
62]
63
57c36b27
C
64// ---------------------------------------------------------------------------
65
66export {
bc99dfe5 67 videosSearchValidator,
7b390964 68 videoChannelsListSearchValidator,
bc99dfe5 69 videoChannelsOwnSearchValidator
57c36b27 70}