aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/search.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-19 16:17:54 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commit57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (patch)
tree87ebcd623c06445b9b25a237addefc98a2d64afa /server/controllers/api/search.ts
parent7279b455811f4806dcb74a08d17b837bc22533c1 (diff)
downloadPeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.gz
PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.zst
PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.zip
Begin advanced search
Diffstat (limited to 'server/controllers/api/search.ts')
-rw-r--r--server/controllers/api/search.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
new file mode 100644
index 000000000..2ff340b59
--- /dev/null
+++ b/server/controllers/api/search.ts
@@ -0,0 +1,43 @@
1import * as express from 'express'
2import { isNSFWHidden } from '../../helpers/express-utils'
3import { getFormattedObjects } from '../../helpers/utils'
4import { VideoModel } from '../../models/video/video'
5import {
6 asyncMiddleware,
7 optionalAuthenticate,
8 paginationValidator,
9 searchValidator,
10 setDefaultPagination,
11 setDefaultSearchSort,
12 videosSearchSortValidator
13} from '../../middlewares'
14
15const searchRouter = express.Router()
16
17searchRouter.get('/videos',
18 paginationValidator,
19 setDefaultPagination,
20 videosSearchSortValidator,
21 setDefaultSearchSort,
22 optionalAuthenticate,
23 searchValidator,
24 asyncMiddleware(searchVideos)
25)
26
27// ---------------------------------------------------------------------------
28
29export { searchRouter }
30
31// ---------------------------------------------------------------------------
32
33async function searchVideos (req: express.Request, res: express.Response) {
34 const resultList = await VideoModel.searchAndPopulateAccountAndServer(
35 req.query.search as string,
36 req.query.start as number,
37 req.query.count as number,
38 req.query.sort as string,
39 isNSFWHidden(res)
40 )
41
42 return res.json(getFormattedObjects(resultList.data, resultList.total))
43}