diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-29 11:54:38 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-29 11:54:38 +0200 |
commit | d6886027109af42be2e3ec5d14ad166199add11d (patch) | |
tree | 3a7603d36ff35a2d623d863f14ab93a2e1e6b7f2 /server/controllers/api/search/search-video-channels.ts | |
parent | b033851fb54241bb703f86add025229e68cc6f59 (diff) | |
download | PeerTube-d6886027109af42be2e3ec5d14ad166199add11d.tar.gz PeerTube-d6886027109af42be2e3ec5d14ad166199add11d.tar.zst PeerTube-d6886027109af42be2e3ec5d14ad166199add11d.zip |
Refactor search query options
Diffstat (limited to 'server/controllers/api/search/search-video-channels.ts')
-rw-r--r-- | server/controllers/api/search/search-video-channels.ts | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/server/controllers/api/search/search-video-channels.ts b/server/controllers/api/search/search-video-channels.ts index ae32a6726..eef222506 100644 --- a/server/controllers/api/search/search-video-channels.ts +++ b/server/controllers/api/search/search-video-channels.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { sanitizeUrl } from '@server/helpers/core-utils' | 2 | import { sanitizeUrl } from '@server/helpers/core-utils' |
3 | import { pickSearchChannelQuery } from '@server/helpers/query' | ||
3 | import { doJSONRequest } from '@server/helpers/requests' | 4 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
5 | import { WEBSERVER } from '@server/initializers/constants' | 6 | import { WEBSERVER } from '@server/initializers/constants' |
@@ -7,7 +8,7 @@ import { Hooks } from '@server/lib/plugins/hooks' | |||
7 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' | 8 | import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' |
8 | import { getServerActor } from '@server/models/application/application' | 9 | import { getServerActor } from '@server/models/application/application' |
9 | import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models' | 10 | import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models' |
10 | import { VideoChannelsSearchQuery } from '../../../../shared/models/search' | 11 | import { VideoChannelsSearchQueryAfterSanitize } from '../../../../shared/models/search' |
11 | import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' | 12 | import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' |
12 | import { logger } from '../../../helpers/logger' | 13 | import { logger } from '../../../helpers/logger' |
13 | import { getFormattedObjects } from '../../../helpers/utils' | 14 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -45,7 +46,7 @@ export { searchChannelsRouter } | |||
45 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
46 | 47 | ||
47 | function searchVideoChannels (req: express.Request, res: express.Response) { | 48 | function searchVideoChannels (req: express.Request, res: express.Response) { |
48 | const query: VideoChannelsSearchQuery = req.query | 49 | const query = pickSearchChannelQuery(req.query) |
49 | let search = query.search || '' | 50 | let search = query.search || '' |
50 | 51 | ||
51 | const parts = search.split('@') | 52 | const parts = search.split('@') |
@@ -66,7 +67,7 @@ function searchVideoChannels (req: express.Request, res: express.Response) { | |||
66 | return searchVideoChannelsDB(query, res) | 67 | return searchVideoChannelsDB(query, res) |
67 | } | 68 | } |
68 | 69 | ||
69 | async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: express.Response) { | 70 | async function searchVideoChannelsIndex (query: VideoChannelsSearchQueryAfterSanitize, res: express.Response) { |
70 | const result = await buildMutedForSearchIndex(res) | 71 | const result = await buildMutedForSearchIndex(res) |
71 | 72 | ||
72 | const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-channels.index.list.params') | 73 | const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-channels.index.list.params') |
@@ -90,17 +91,13 @@ async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: e | |||
90 | } | 91 | } |
91 | } | 92 | } |
92 | 93 | ||
93 | async function searchVideoChannelsDB (query: VideoChannelsSearchQuery, res: express.Response) { | 94 | async function searchVideoChannelsDB (query: VideoChannelsSearchQueryAfterSanitize, res: express.Response) { |
94 | const serverActor = await getServerActor() | 95 | const serverActor = await getServerActor() |
95 | 96 | ||
96 | const apiOptions = await Hooks.wrapObject({ | 97 | const apiOptions = await Hooks.wrapObject({ |
97 | actorId: serverActor.id, | 98 | ...query, |
98 | search: query.search, | 99 | |
99 | start: query.start, | 100 | actorId: serverActor.id |
100 | count: query.count, | ||
101 | sort: query.sort, | ||
102 | host: query.host, | ||
103 | handles: query.handles | ||
104 | }, 'filter:api.search.video-channels.local.list.params') | 101 | }, 'filter:api.search.video-channels.local.list.params') |
105 | 102 | ||
106 | const resultList = await Hooks.wrapPromiseFun( | 103 | const resultList = await Hooks.wrapPromiseFun( |