1 import * as express from 'express'
2 import { areValidationErrors } from './utils'
3 import { logger } from '../../helpers/logger'
4 import { query } from 'express-validator/check'
5 import { isNumberArray, isStringArray, isNSFWQueryValid } from '../../helpers/custom-validators/search'
6 import { isBooleanValid, isDateValid, toArray } from '../../helpers/custom-validators/misc'
8 const videosSearchValidator = [
9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
11 query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
12 query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),
14 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
15 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
17 (req: express.Request, res: express.Response, next: express.NextFunction) => {
18 logger.debug('Checking videos search query', { parameters: req.query })
20 if (areValidationErrors(req, res)) return
26 const videoChannelsSearchValidator = [
27 query('search').not().isEmpty().withMessage('Should have a valid search'),
29 (req: express.Request, res: express.Response, next: express.NextFunction) => {
30 logger.debug('Checking video channels search query', { parameters: req.query })
32 if (areValidationErrors(req, res)) return
38 const commonVideosFiltersValidator = [
39 query('categoryOneOf')
41 .customSanitizer(toArray)
42 .custom(isNumberArray).withMessage('Should have a valid one of category array'),
45 .customSanitizer(toArray)
46 .custom(isNumberArray).withMessage('Should have a valid one of licence array'),
47 query('languageOneOf')
49 .customSanitizer(toArray)
50 .custom(isStringArray).withMessage('Should have a valid one of language array'),
53 .customSanitizer(toArray)
54 .custom(isStringArray).withMessage('Should have a valid one of tags array'),
57 .customSanitizer(toArray)
58 .custom(isStringArray).withMessage('Should have a valid all of tags array'),
61 .custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'),
63 (req: express.Request, res: express.Response, next: express.NextFunction) => {
64 logger.debug('Checking commons video filters query', { parameters: req.query })
66 if (areValidationErrors(req, res)) return
72 // ---------------------------------------------------------------------------
75 commonVideosFiltersValidator,
76 videoChannelsSearchValidator,