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, isNotEmptyStringArray, 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'),
70 .custom(isNotEmptyStringArray).withMessage('Should have valid handles'),
72 (req: express.Request, res: express.Response, next: express.NextFunction) => {
73 logger.debug('Checking video channels search query', { parameters: req.query })
75 if (areValidationErrors(req, res)) return
81 const videoPlaylistsListSearchValidator = [
84 .not().isEmpty().withMessage('Should have a valid search'),
88 .custom(isHostValid).withMessage('Should have a valid host'),
92 .custom(isSearchTargetValid).withMessage('Should have a valid search target'),
97 .customSanitizer(toCompleteUUIDs)
98 .custom(areUUIDsValid).withMessage('Should have valid uuids'),
100 (req: express.Request, res: express.Response, next: express.NextFunction) => {
101 logger.debug('Checking video playlists search query', { parameters: req.query })
103 if (areValidationErrors(req, res)) return
109 // ---------------------------------------------------------------------------
112 videosSearchValidator,
113 videoChannelsListSearchValidator,
114 videoPlaylistsListSearchValidator