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 { areUUIDsValid, isDateValid, toCompleteUUIDs } 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'),
32 .isInt().withMessage('Should have a valid min duration'),
35 .isInt().withMessage('Should have a valid max duration'),
40 .customSanitizer(toCompleteUUIDs)
41 .custom(areUUIDsValid).withMessage('Should have valid uuids'),
43 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
45 (req: express.Request, res: express.Response, next: express.NextFunction) => {
46 logger.debug('Checking videos search query', { parameters: req.query })
48 if (areValidationErrors(req, res)) return
54 const videoChannelsListSearchValidator = [
57 .not().isEmpty().withMessage('Should have a valid search'),
61 .custom(isHostValid).withMessage('Should have a valid host'),
65 .custom(isSearchTargetValid).withMessage('Should have a valid search target'),
71 (req: express.Request, res: express.Response, next: express.NextFunction) => {
72 logger.debug('Checking video channels search query', { parameters: req.query })
74 if (areValidationErrors(req, res)) return
80 const videoPlaylistsListSearchValidator = [
83 .not().isEmpty().withMessage('Should have a valid search'),
87 .custom(isHostValid).withMessage('Should have a valid host'),
91 .custom(isSearchTargetValid).withMessage('Should have a valid search target'),
96 .customSanitizer(toCompleteUUIDs)
97 .custom(areUUIDsValid).withMessage('Should have valid uuids'),
99 (req: express.Request, res: express.Response, next: express.NextFunction) => {
100 logger.debug('Checking video playlists search query', { parameters: req.query })
102 if (areValidationErrors(req, res)) return
108 // ---------------------------------------------------------------------------
111 videosSearchValidator,
112 videoChannelsListSearchValidator,
113 videoPlaylistsListSearchValidator