diff options
Diffstat (limited to 'server/controllers/api/search.ts')
-rw-r--r-- | server/controllers/api/search.ts | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts index 2ff340b59..f810c7452 100644 --- a/server/controllers/api/search.ts +++ b/server/controllers/api/search.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { isNSFWHidden } from '../../helpers/express-utils' | 2 | import { buildNSFWFilter } from '../../helpers/express-utils' |
3 | import { getFormattedObjects } from '../../helpers/utils' | 3 | import { getFormattedObjects } from '../../helpers/utils' |
4 | import { VideoModel } from '../../models/video/video' | 4 | import { VideoModel } from '../../models/video/video' |
5 | import { | 5 | import { |
6 | asyncMiddleware, | 6 | asyncMiddleware, |
7 | commonVideosFiltersValidator, | ||
7 | optionalAuthenticate, | 8 | optionalAuthenticate, |
8 | paginationValidator, | 9 | paginationValidator, |
9 | searchValidator, | 10 | searchValidator, |
@@ -11,6 +12,7 @@ import { | |||
11 | setDefaultSearchSort, | 12 | setDefaultSearchSort, |
12 | videosSearchSortValidator | 13 | videosSearchSortValidator |
13 | } from '../../middlewares' | 14 | } from '../../middlewares' |
15 | import { VideosSearchQuery } from '../../../shared/models/search' | ||
14 | 16 | ||
15 | const searchRouter = express.Router() | 17 | const searchRouter = express.Router() |
16 | 18 | ||
@@ -20,6 +22,7 @@ searchRouter.get('/videos', | |||
20 | videosSearchSortValidator, | 22 | videosSearchSortValidator, |
21 | setDefaultSearchSort, | 23 | setDefaultSearchSort, |
22 | optionalAuthenticate, | 24 | optionalAuthenticate, |
25 | commonVideosFiltersValidator, | ||
23 | searchValidator, | 26 | searchValidator, |
24 | asyncMiddleware(searchVideos) | 27 | asyncMiddleware(searchVideos) |
25 | ) | 28 | ) |
@@ -31,13 +34,10 @@ export { searchRouter } | |||
31 | // --------------------------------------------------------------------------- | 34 | // --------------------------------------------------------------------------- |
32 | 35 | ||
33 | async function searchVideos (req: express.Request, res: express.Response) { | 36 | async function searchVideos (req: express.Request, res: express.Response) { |
34 | const resultList = await VideoModel.searchAndPopulateAccountAndServer( | 37 | const query: VideosSearchQuery = req.query |
35 | req.query.search as string, | 38 | |
36 | req.query.start as number, | 39 | const options = Object.assign(query, { nsfw: buildNSFWFilter(res, query.nsfw) }) |
37 | req.query.count as number, | 40 | const resultList = await VideoModel.searchAndPopulateAccountAndServer(options) |
38 | req.query.sort as string, | ||
39 | isNSFWHidden(res) | ||
40 | ) | ||
41 | 41 | ||
42 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 42 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
43 | } | 43 | } |