aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/search.ts34
1 files changed, 29 insertions, 5 deletions
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts
index ea6a490b2..cde300968 100644
--- a/server/middlewares/validators/search.ts
+++ b/server/middlewares/validators/search.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import { query } from 'express-validator' 2import { query } from 'express-validator'
3import { isSearchTargetValid } from '@server/helpers/custom-validators/search' 3import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
4import { isHostValid } from '@server/helpers/custom-validators/servers' 4import { isHostValid } from '@server/helpers/custom-validators/servers'
5import { isDateValid } from '../../helpers/custom-validators/misc' 5import { areUUIDsValid, isDateValid, toCompleteUUIDs } from '../../helpers/custom-validators/misc'
6import { logger } from '../../helpers/logger' 6import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './shared' 7import { areValidationErrors } from './shared'
8 8
@@ -27,8 +27,18 @@ const videosSearchValidator = [
27 .optional() 27 .optional()
28 .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), 28 .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'),
29 29
30 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), 30 query('durationMin')
31 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), 31 .optional()
32 .isInt().withMessage('Should have a valid min duration'),
33 query('durationMax')
34 .optional()
35 .isInt().withMessage('Should have a valid max duration'),
36
37 query('uuids')
38 .optional()
39 .toArray()
40 .customSanitizer(toCompleteUUIDs)
41 .custom(areUUIDsValid).withMessage('Should have valid uuids'),
32 42
33 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), 43 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
34 44
@@ -42,7 +52,9 @@ const videosSearchValidator = [
42] 52]
43 53
44const videoChannelsListSearchValidator = [ 54const videoChannelsListSearchValidator = [
45 query('search').not().isEmpty().withMessage('Should have a valid search'), 55 query('search')
56 .optional()
57 .not().isEmpty().withMessage('Should have a valid search'),
46 58
47 query('host') 59 query('host')
48 .optional() 60 .optional()
@@ -52,6 +64,10 @@ const videoChannelsListSearchValidator = [
52 .optional() 64 .optional()
53 .custom(isSearchTargetValid).withMessage('Should have a valid search target'), 65 .custom(isSearchTargetValid).withMessage('Should have a valid search target'),
54 66
67 query('names')
68 .optional()
69 .toArray(),
70
55 (req: express.Request, res: express.Response, next: express.NextFunction) => { 71 (req: express.Request, res: express.Response, next: express.NextFunction) => {
56 logger.debug('Checking video channels search query', { parameters: req.query }) 72 logger.debug('Checking video channels search query', { parameters: req.query })
57 73
@@ -62,7 +78,9 @@ const videoChannelsListSearchValidator = [
62] 78]
63 79
64const videoPlaylistsListSearchValidator = [ 80const videoPlaylistsListSearchValidator = [
65 query('search').not().isEmpty().withMessage('Should have a valid search'), 81 query('search')
82 .optional()
83 .not().isEmpty().withMessage('Should have a valid search'),
66 84
67 query('host') 85 query('host')
68 .optional() 86 .optional()
@@ -72,6 +90,12 @@ const videoPlaylistsListSearchValidator = [
72 .optional() 90 .optional()
73 .custom(isSearchTargetValid).withMessage('Should have a valid search target'), 91 .custom(isSearchTargetValid).withMessage('Should have a valid search target'),
74 92
93 query('uuids')
94 .optional()
95 .toArray()
96 .customSanitizer(toCompleteUUIDs)
97 .custom(areUUIDsValid).withMessage('Should have valid uuids'),
98
75 (req: express.Request, res: express.Response, next: express.NextFunction) => { 99 (req: express.Request, res: express.Response, next: express.NextFunction) => {
76 logger.debug('Checking video playlists search query', { parameters: req.query }) 100 logger.debug('Checking video playlists search query', { parameters: req.query })
77 101