diff options
Diffstat (limited to 'server/controllers/api/search/search-video-channels.ts')
-rw-r--r-- | server/controllers/api/search/search-video-channels.ts | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/server/controllers/api/search/search-video-channels.ts b/server/controllers/api/search/search-video-channels.ts index 16beeed60..eef222506 100644 --- a/server/controllers/api/search/search-video-channels.ts +++ b/server/controllers/api/search/search-video-channels.ts | |||
@@ -1,14 +1,14 @@ | |||
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' |
6 | import { Hooks } from '@server/lib/plugins/hooks' | 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 } from '@shared/core-utils/miscs/http-error-codes' | 10 | import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models' |
10 | import { ResultList, VideoChannel } from '@shared/models' | 11 | import { VideoChannelsSearchQueryAfterSanitize } from '../../../../shared/models/search' |
11 | import { VideoChannelsSearchQuery } from '../../../../shared/models/search' | ||
12 | import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' | 12 | import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' |
13 | import { logger } from '../../../helpers/logger' | 13 | import { logger } from '../../../helpers/logger' |
14 | import { getFormattedObjects } from '../../../helpers/utils' | 14 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -46,8 +46,8 @@ export { searchChannelsRouter } | |||
46 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
47 | 47 | ||
48 | function searchVideoChannels (req: express.Request, res: express.Response) { | 48 | function searchVideoChannels (req: express.Request, res: express.Response) { |
49 | const query: VideoChannelsSearchQuery = req.query | 49 | const query = pickSearchChannelQuery(req.query) |
50 | const search = query.search | 50 | let search = query.search || '' |
51 | 51 | ||
52 | const parts = search.split('@') | 52 | const parts = search.split('@') |
53 | 53 | ||
@@ -58,7 +58,7 @@ function searchVideoChannels (req: express.Request, res: express.Response) { | |||
58 | if (isURISearch(search) || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res) | 58 | if (isURISearch(search) || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res) |
59 | 59 | ||
60 | // @username -> username to search in DB | 60 | // @username -> username to search in DB |
61 | if (query.search.startsWith('@')) query.search = query.search.replace(/^@/, '') | 61 | if (search.startsWith('@')) search = search.replace(/^@/, '') |
62 | 62 | ||
63 | if (isSearchIndexSearch(query)) { | 63 | if (isSearchIndexSearch(query)) { |
64 | return searchVideoChannelsIndex(query, res) | 64 | return searchVideoChannelsIndex(query, res) |
@@ -67,7 +67,7 @@ function searchVideoChannels (req: express.Request, res: express.Response) { | |||
67 | return searchVideoChannelsDB(query, res) | 67 | return searchVideoChannelsDB(query, res) |
68 | } | 68 | } |
69 | 69 | ||
70 | async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: express.Response) { | 70 | async function searchVideoChannelsIndex (query: VideoChannelsSearchQueryAfterSanitize, res: express.Response) { |
71 | const result = await buildMutedForSearchIndex(res) | 71 | const result = await buildMutedForSearchIndex(res) |
72 | 72 | ||
73 | 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') |
@@ -91,15 +91,13 @@ async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: e | |||
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | async function searchVideoChannelsDB (query: VideoChannelsSearchQuery, res: express.Response) { | 94 | async function searchVideoChannelsDB (query: VideoChannelsSearchQueryAfterSanitize, res: express.Response) { |
95 | const serverActor = await getServerActor() | 95 | const serverActor = await getServerActor() |
96 | 96 | ||
97 | const apiOptions = await Hooks.wrapObject({ | 97 | const apiOptions = await Hooks.wrapObject({ |
98 | actorId: serverActor.id, | 98 | ...query, |
99 | search: query.search, | 99 | |
100 | start: query.start, | 100 | actorId: serverActor.id |
101 | count: query.count, | ||
102 | sort: query.sort | ||
103 | }, 'filter:api.search.video-channels.local.list.params') | 101 | }, 'filter:api.search.video-channels.local.list.params') |
104 | 102 | ||
105 | const resultList = await Hooks.wrapPromiseFun( | 103 | const resultList = await Hooks.wrapPromiseFun( |