1 import * as express from 'express'
2 import { query } from 'express-validator'
3 import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
4 import { isDateValid } from '../../helpers/custom-validators/misc'
5 import { logger } from '../../helpers/logger'
6 import { areValidationErrors } from './shared'
8 const videosSearchValidator = [
9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
13 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
16 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
18 query('originallyPublishedStartDate')
20 .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'),
21 query('originallyPublishedEndDate')
23 .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'),
25 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
26 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
28 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
30 (req: express.Request, res: express.Response, next: express.NextFunction) => {
31 logger.debug('Checking videos search query', { parameters: req.query })
33 if (areValidationErrors(req, res)) return
39 const videoChannelsListSearchValidator = [
40 query('search').not().isEmpty().withMessage('Should have a valid search'),
41 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
43 (req: express.Request, res: express.Response, next: express.NextFunction) => {
44 logger.debug('Checking video channels search query', { parameters: req.query })
46 if (areValidationErrors(req, res)) return
52 const videoChannelsOwnSearchValidator = [
53 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
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 // ---------------------------------------------------------------------------
67 videosSearchValidator,
68 videoChannelsListSearchValidator,
69 videoChannelsOwnSearchValidator