diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-19 16:17:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-24 14:04:05 +0200 |
commit | 57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (patch) | |
tree | 87ebcd623c06445b9b25a237addefc98a2d64afa /server/middlewares/validators | |
parent | 7279b455811f4806dcb74a08d17b837bc22533c1 (diff) | |
download | PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.gz PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.zst PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.zip |
Begin advanced search
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/search.ts | 22 | ||||
-rw-r--r-- | server/middlewares/validators/sort.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/videos.ts | 15 |
4 files changed, 27 insertions, 14 deletions
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index b69e1f14b..e3f0f5963 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -10,3 +10,4 @@ export * from './videos' | |||
10 | export * from './video-blacklist' | 10 | export * from './video-blacklist' |
11 | export * from './video-channels' | 11 | export * from './video-channels' |
12 | export * from './webfinger' | 12 | export * from './webfinger' |
13 | export * from './search' | ||
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts new file mode 100644 index 000000000..774845e8a --- /dev/null +++ b/server/middlewares/validators/search.ts | |||
@@ -0,0 +1,22 @@ | |||
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 | |||
6 | const searchValidator = [ | ||
7 | query('search').not().isEmpty().withMessage('Should have a valid search'), | ||
8 | |||
9 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
10 | logger.debug('Checking search parameters', { parameters: req.params }) | ||
11 | |||
12 | if (areValidationErrors(req, res)) return | ||
13 | |||
14 | return next() | ||
15 | } | ||
16 | ] | ||
17 | |||
18 | // --------------------------------------------------------------------------- | ||
19 | |||
20 | export { | ||
21 | searchValidator | ||
22 | } | ||
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index 925f47e57..00bde548c 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts | |||
@@ -7,6 +7,7 @@ const SORTABLE_ACCOUNTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.ACCOUNT | |||
7 | const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS) | 7 | const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS) |
8 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) | 8 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) |
9 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) | 9 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) |
10 | const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH) | ||
10 | const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) | 11 | const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) |
11 | const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) | 12 | const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) |
12 | const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS) | 13 | const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS) |
@@ -18,6 +19,7 @@ const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) | |||
18 | const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS) | 19 | const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS) |
19 | const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) | 20 | const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) |
20 | const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) | 21 | const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) |
22 | const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS) | ||
21 | const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) | 23 | const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) |
22 | const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) | 24 | const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) |
23 | const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) | 25 | const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) |
@@ -30,6 +32,7 @@ export { | |||
30 | usersSortValidator, | 32 | usersSortValidator, |
31 | videoAbusesSortValidator, | 33 | videoAbusesSortValidator, |
32 | videoChannelsSortValidator, | 34 | videoChannelsSortValidator, |
35 | videosSearchSortValidator, | ||
33 | videosSortValidator, | 36 | videosSortValidator, |
34 | blacklistSortValidator, | 37 | blacklistSortValidator, |
35 | accountsSortValidator, | 38 | accountsSortValidator, |
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index abb23b510..d9af2aa0a 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, query, ValidationChain } from 'express-validator/check' | 3 | import { body, param, ValidationChain } from 'express-validator/check' |
4 | import { UserRight, VideoPrivacy } from '../../../shared' | 4 | import { UserRight, VideoPrivacy } from '../../../shared' |
5 | import { | 5 | import { |
6 | isBooleanValid, | 6 | isBooleanValid, |
@@ -172,18 +172,6 @@ const videosRemoveValidator = [ | |||
172 | } | 172 | } |
173 | ] | 173 | ] |
174 | 174 | ||
175 | const videosSearchValidator = [ | ||
176 | query('search').not().isEmpty().withMessage('Should have a valid search'), | ||
177 | |||
178 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
179 | logger.debug('Checking videosSearch parameters', { parameters: req.params }) | ||
180 | |||
181 | if (areValidationErrors(req, res)) return | ||
182 | |||
183 | return next() | ||
184 | } | ||
185 | ] | ||
186 | |||
187 | const videoAbuseReportValidator = [ | 175 | const videoAbuseReportValidator = [ |
188 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 176 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
189 | body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), | 177 | body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), |
@@ -240,7 +228,6 @@ export { | |||
240 | videosUpdateValidator, | 228 | videosUpdateValidator, |
241 | videosGetValidator, | 229 | videosGetValidator, |
242 | videosRemoveValidator, | 230 | videosRemoveValidator, |
243 | videosSearchValidator, | ||
244 | videosShareValidator, | 231 | videosShareValidator, |
245 | 232 | ||
246 | videoAbuseReportValidator, | 233 | videoAbuseReportValidator, |