Support POST method for search endpoints

This commit is contained in:
Chocobozzz 2021-03-10 09:09:04 +01:00
parent a040b384ef
commit 1afdaf3f0b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 32 additions and 11 deletions

View File

@ -1,17 +1,19 @@
import * as express from 'express'
import { ChannelsSearchQuery } from 'server/types/channel-search.model'
import { CONFIG } from '../../initializers/constants'
import { formatChannelForAPI, queryChannels } from '../../lib/elastic-search-channels'
import { asyncMiddleware } from '../../middlewares/async'
import { setDefaultPagination } from '../../middlewares/pagination'
import { setDefaultSearchSort } from '../../middlewares/sort'
import { methodsValidator } from '../../middlewares/validators/method'
import { paginationValidator } from '../../middlewares/validators/pagination'
import { videoChannelsSearchValidator, commonFiltersValidators } from '../../middlewares/validators/search'
import { commonFiltersValidators, videoChannelsSearchValidator } from '../../middlewares/validators/search'
import { channelsSearchSortValidator } from '../../middlewares/validators/sort'
import { CONFIG } from '../../initializers/constants'
const searchChannelsRouter = express.Router()
searchChannelsRouter.get('/search/video-channels',
searchChannelsRouter.all('/search/video-channels',
methodsValidator([ 'POST', 'GET' ]),
paginationValidator,
setDefaultPagination,
channelsSearchSortValidator,

View File

@ -1,17 +1,19 @@
import * as express from 'express'
import { paginationValidator } from '../../middlewares/validators/pagination'
import { setDefaultPagination } from '../../middlewares/pagination'
import { asyncMiddleware } from '../../middlewares/async'
import { formatVideoForAPI, queryVideos } from '../../lib/elastic-search-videos'
import { videosSearchSortValidator } from '../../middlewares/validators/sort'
import { commonVideosFiltersValidator, videosSearchValidator, commonFiltersValidators } from '../../middlewares/validators/search'
import { setDefaultSearchSort } from '../../middlewares/sort'
import { VideosSearchQuery } from 'server/types/video-search.model'
import { CONFIG } from '../../initializers/constants'
import { formatVideoForAPI, queryVideos } from '../../lib/elastic-search-videos'
import { asyncMiddleware } from '../../middlewares/async'
import { setDefaultPagination } from '../../middlewares/pagination'
import { setDefaultSearchSort } from '../../middlewares/sort'
import { methodsValidator } from '../../middlewares/validators/method'
import { paginationValidator } from '../../middlewares/validators/pagination'
import { commonFiltersValidators, commonVideosFiltersValidator, videosSearchValidator } from '../../middlewares/validators/search'
import { videosSearchSortValidator } from '../../middlewares/validators/sort'
const searchVideosRouter = express.Router()
searchVideosRouter.get('/search/videos',
searchVideosRouter.all('/search/videos',
methodsValidator([ 'POST', 'GET' ]),
paginationValidator,
setDefaultPagination,
videosSearchSortValidator,

View File

@ -0,0 +1,17 @@
import * as express from 'express'
const methodsValidator = (methods: string[]) => {
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (methods.includes(req.method) !== true) {
return res.sendStatus(405)
}
return next()
}
}
// ---------------------------------------------------------------------------
export {
methodsValidator
}