1 import * as express from 'express'
2 import { query } from 'express-validator'
3 import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
4 import { isHostValid } from '@server/helpers/custom-validators/servers'
5 import { isDateValid } from '../../helpers/custom-validators/misc'
6 import { logger } from '../../helpers/logger'
7 import { areValidationErrors } from './shared'
9 const videosSearchValidator = [
10 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
14 .custom(isHostValid).withMessage('Should have a valid host'),
18 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
21 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
23 query('originallyPublishedStartDate')
25 .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'),
26 query('originallyPublishedEndDate')
28 .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'),
30 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
31 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
33 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
35 (req: express.Request, res: express.Response, next: express.NextFunction) => {
36 logger.debug('Checking videos search query', { parameters: req.query })
38 if (areValidationErrors(req, res)) return
44 const videoChannelsListSearchValidator = [
45 query('search').not().isEmpty().withMessage('Should have a valid search'),
49 .custom(isHostValid).withMessage('Should have a valid host'),
53 .custom(isSearchTargetValid).withMessage('Should have a valid search target'),
55 (req: express.Request, res: express.Response, next: express.NextFunction) => {
56 logger.debug('Checking video channels search query', { parameters: req.query })
58 if (areValidationErrors(req, res)) return
64 const videoPlaylistsListSearchValidator = [
65 query('search').not().isEmpty().withMessage('Should have a valid search'),
69 .custom(isHostValid).withMessage('Should have a valid host'),
73 .custom(isSearchTargetValid).withMessage('Should have a valid search target'),
75 (req: express.Request, res: express.Response, next: express.NextFunction) => {
76 logger.debug('Checking video playlists search query', { parameters: req.query })
78 if (areValidationErrors(req, res)) return
84 // ---------------------------------------------------------------------------
87 videosSearchValidator,
88 videoChannelsListSearchValidator,
89 videoPlaylistsListSearchValidator