From 57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Jul 2018 16:17:54 +0200 Subject: Begin advanced search --- server/middlewares/validators/index.ts | 1 + server/middlewares/validators/search.ts | 22 ++++++++++++++++++++++ server/middlewares/validators/sort.ts | 3 +++ server/middlewares/validators/videos.ts | 15 +-------------- 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 server/middlewares/validators/search.ts (limited to 'server/middlewares/validators') 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' export * from './video-blacklist' export * from './video-channels' export * from './webfinger' +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 @@ +import * as express from 'express' +import { areValidationErrors } from './utils' +import { logger } from '../../helpers/logger' +import { query } from 'express-validator/check' + +const searchValidator = [ + query('search').not().isEmpty().withMessage('Should have a valid search'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking search parameters', { parameters: req.params }) + + if (areValidationErrors(req, res)) return + + return next() + } +] + +// --------------------------------------------------------------------------- + +export { + searchValidator +} 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 const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS) const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) +const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH) const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS) @@ -18,6 +19,7 @@ const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS) const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) +const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS) const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) @@ -30,6 +32,7 @@ export { usersSortValidator, videoAbusesSortValidator, videoChannelsSortValidator, + videosSearchSortValidator, videosSortValidator, blacklistSortValidator, 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 @@ import * as express from 'express' import 'express-validator' -import { body, param, query, ValidationChain } from 'express-validator/check' +import { body, param, ValidationChain } from 'express-validator/check' import { UserRight, VideoPrivacy } from '../../../shared' import { isBooleanValid, @@ -172,18 +172,6 @@ const videosRemoveValidator = [ } ] -const videosSearchValidator = [ - query('search').not().isEmpty().withMessage('Should have a valid search'), - - (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking videosSearch parameters', { parameters: req.params }) - - if (areValidationErrors(req, res)) return - - return next() - } -] - const videoAbuseReportValidator = [ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), @@ -240,7 +228,6 @@ export { videosUpdateValidator, videosGetValidator, videosRemoveValidator, - videosSearchValidator, videosShareValidator, videoAbuseReportValidator, -- cgit v1.2.3