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 } from '../../middlewares/validators/search' import { setDefaultSearchSort } from '../../middlewares/sort' const searchRouter = express.Router() searchRouter.get('/search/videos', paginationValidator, setDefaultPagination, videosSearchSortValidator, setDefaultSearchSort, commonVideosFiltersValidator, videosSearchValidator, asyncMiddleware(searchVideos) ) // --------------------------------------------------------------------------- export { searchRouter } // --------------------------------------------------------------------------- async function searchVideos (req: express.Request, res: express.Response) { const resultList = await queryVideos(req.query) return res.json({ total: resultList.total, data: resultList.data.map(v => formatVideoForAPI(v, req.query.fromHost)) }) }