diff --git a/server/controllers/api/search-channels.ts b/server/controllers/api/search-channels.ts index 796da41..ddb8a1c 100644 --- a/server/controllers/api/search-channels.ts +++ b/server/controllers/api/search-channels.ts @@ -27,7 +27,7 @@ export { searchChannelsRouter } // --------------------------------------------------------------------------- async function searchChannels (req: express.Request, res: express.Response) { - const query = req.query as ChannelsSearchQuery + const query = (req.query || req.body) as ChannelsSearchQuery const resultList = await queryChannels(query) return res.json({ diff --git a/server/controllers/api/search-videos.ts b/server/controllers/api/search-videos.ts index 33c0bc2..5280df4 100644 --- a/server/controllers/api/search-videos.ts +++ b/server/controllers/api/search-videos.ts @@ -28,7 +28,7 @@ export { searchVideosRouter } // --------------------------------------------------------------------------- async function searchVideos (req: express.Request, res: express.Response) { - const query = req.query as VideosSearchQuery + const query = (req.query || req.body) as VideosSearchQuery const resultList = await queryVideos(query) diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts index 4bd20ad..1621c4c 100644 --- a/server/middlewares/validators/pagination.ts +++ b/server/middlewares/validators/pagination.ts @@ -1,11 +1,11 @@ import * as express from 'express' -import { query } from 'express-validator' +import { check } from 'express-validator' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' const paginationValidator = [ - query('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'), - query('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'), + check('start').optional().isInt({ min: 0 }).withMessage('Should have a number start'), + check('count').optional().isInt({ min: 0 }).withMessage('Should have a number count'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug({ parameters: req.query }, 'Checking pagination parameters') diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 6bc6195..46cc32d 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts @@ -1,4 +1,4 @@ -import { query } from 'express-validator' +import { check } from 'express-validator' import * as express from 'express' import { isDateValid, toArray } from '../../helpers/custom-validators/misc' import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../helpers/custom-validators/search-videos' @@ -6,11 +6,11 @@ import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' const commonFiltersValidators = [ - query('blockedAccounts') + check('blockedAccounts') .optional() .customSanitizer(toArray) .custom(isStringArray).withMessage('Should have a valid blockedAccounts array'), - query('blockedHosts') + check('blockedHosts') .optional() .customSanitizer(toArray) .custom(isStringArray).withMessage('Should have a valid hosts array'), @@ -25,27 +25,27 @@ const commonFiltersValidators = [ ] const commonVideosFiltersValidator = [ - query('categoryOneOf') + check('categoryOneOf') .optional() .customSanitizer(toArray) .custom(isNumberArray).withMessage('Should have a valid one of category array'), - query('licenceOneOf') + check('licenceOneOf') .optional() .customSanitizer(toArray) .custom(isNumberArray).withMessage('Should have a valid one of licence array'), - query('languageOneOf') + check('languageOneOf') .optional() .customSanitizer(toArray) .custom(isStringArray).withMessage('Should have a valid one of language array'), - query('tagsOneOf') + check('tagsOneOf') .optional() .customSanitizer(toArray) .custom(isStringArray).withMessage('Should have a valid one of tags array'), - query('tagsAllOf') + check('tagsAllOf') .optional() .customSanitizer(toArray) .custom(isStringArray).withMessage('Should have a valid all of tags array'), - query('nsfw') + check('nsfw') .optional() .custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'), @@ -59,16 +59,16 @@ const commonVideosFiltersValidator = [ ] const videosSearchValidator = [ - query('search').optional().not().isEmpty().withMessage('Should have a valid search'), + check('search').optional().not().isEmpty().withMessage('Should have a valid search'), - query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'), - query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'), + check('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'), + check('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'), - query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'), - query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'), + check('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'), + check('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'), - query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), - query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), + check('durationMin').optional().isInt().withMessage('Should have a valid min duration'), + check('durationMax').optional().isInt().withMessage('Should have a valid max duration'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug({ parameters: req.query }, 'Checking videos search query') @@ -80,7 +80,7 @@ const videosSearchValidator = [ ] const videoChannelsSearchValidator = [ - query('search').not().isEmpty().withMessage('Should have a valid search'), + check('search').not().isEmpty().withMessage('Should have a valid search'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug({ parameters: req.query }, 'Checking video channels search query') diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 618c417..c02a7c5 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts @@ -1,5 +1,5 @@ import * as express from 'express' -import { query, validationResult } from 'express-validator' +import { check, validationResult } from 'express-validator' import { logger } from '../../helpers/logger' function areValidationErrors (req: express.Request, res: express.Response) { @@ -17,7 +17,7 @@ function areValidationErrors (req: express.Request, res: express.Response) { function checkSort (sortableColumns: string[]) { return [ - query('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'), + check('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'), (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug({ parameters: req.query }, 'Checking sort parameters')