aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/sort.ts7
-rw-r--r--server/middlewares/validators/index.ts1
-rw-r--r--server/middlewares/validators/search.ts22
-rw-r--r--server/middlewares/validators/sort.ts3
-rw-r--r--server/middlewares/validators/videos.ts15
5 files changed, 34 insertions, 14 deletions
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index cdb809e75..6307ee154 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -8,6 +8,12 @@ function setDefaultSort (req: express.Request, res: express.Response, next: expr
8 return next() 8 return next()
9} 9}
10 10
11function setDefaultSearchSort (req: express.Request, res: express.Response, next: express.NextFunction) {
12 if (!req.query.sort) req.query.sort = '-bestmatch'
13
14 return next()
15}
16
11function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) { 17function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
12 let newSort: SortType = { sortModel: undefined, sortValue: undefined } 18 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
13 19
@@ -33,5 +39,6 @@ function setBlacklistSort (req: express.Request, res: express.Response, next: ex
33 39
34export { 40export {
35 setDefaultSort, 41 setDefaultSort,
42 setDefaultSearchSort,
36 setBlacklistSort 43 setBlacklistSort
37} 44}
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'
10export * from './video-blacklist' 10export * from './video-blacklist'
11export * from './video-channels' 11export * from './video-channels'
12export * from './webfinger' 12export * from './webfinger'
13export * 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 @@
1import * as express from 'express'
2import { areValidationErrors } from './utils'
3import { logger } from '../../helpers/logger'
4import { query } from 'express-validator/check'
5
6const 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
20export {
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
7const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS) 7const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS)
8const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) 8const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES)
9const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) 9const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS)
10const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH)
10const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) 11const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS)
11const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) 12const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS)
12const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS) 13const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS)
@@ -18,6 +19,7 @@ const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS)
18const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS) 19const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS)
19const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) 20const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS)
20const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) 21const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS)
22const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS)
21const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) 23const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS)
22const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) 24const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS)
23const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) 25const 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param, query, ValidationChain } from 'express-validator/check' 3import { body, param, ValidationChain } from 'express-validator/check'
4import { UserRight, VideoPrivacy } from '../../../shared' 4import { UserRight, VideoPrivacy } from '../../../shared'
5import { 5import {
6 isBooleanValid, 6 isBooleanValid,
@@ -172,18 +172,6 @@ const videosRemoveValidator = [
172 } 172 }
173] 173]
174 174
175const 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
187const videoAbuseReportValidator = [ 175const 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,