1 import 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 = [
20 .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
23 .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
25 query('originallyPublishedStartDate')
27 .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'),
28 query('originallyPublishedEndDate')
30 .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'),
42 .customSanitizer(toCompleteUUIDs)
43 .custom(areUUIDsValid).withMessage('Should have valid array of uuid'),
47 .custom(isSearchTargetValid),
49 (req: express.Request, res: express.Response, next: express.NextFunction) => {
50 logger.debug('Checking videos search query', { parameters: req.query })
52 if (areValidationErrors(req, res)) return
58 const videoChannelsListSearchValidator = [
69 .custom(isSearchTargetValid),
74 .custom(isNotEmptyStringArray).withMessage('Should have valid array of handles'),
76 (req: express.Request, res: express.Response, next: express.NextFunction) => {
77 logger.debug('Checking video channels search query', { parameters: req.query })
79 if (areValidationErrors(req, res)) return
85 const videoPlaylistsListSearchValidator = [
96 .custom(isSearchTargetValid),
101 .customSanitizer(toCompleteUUIDs)
102 .custom(areUUIDsValid).withMessage('Should have valid array of uuid'),
104 (req: express.Request, res: express.Response, next: express.NextFunction) => {
105 logger.debug('Checking video playlists search query', { parameters: req.query })
107 if (areValidationErrors(req, res)) return
113 // ---------------------------------------------------------------------------
116 videosSearchValidator,
117 videoChannelsListSearchValidator,
118 videoPlaylistsListSearchValidator