aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/search/search-video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/search/search-video-channels.ts')
-rw-r--r--server/controllers/api/search/search-video-channels.ts24
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { sanitizeUrl } from '@server/helpers/core-utils' 2import { sanitizeUrl } from '@server/helpers/core-utils'
3import { pickSearchChannelQuery } from '@server/helpers/query'
3import { doJSONRequest } from '@server/helpers/requests' 4import { doJSONRequest } from '@server/helpers/requests'
4import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
5import { WEBSERVER } from '@server/initializers/constants' 6import { WEBSERVER } from '@server/initializers/constants'
6import { Hooks } from '@server/lib/plugins/hooks' 7import { Hooks } from '@server/lib/plugins/hooks'
7import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' 8import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search'
8import { getServerActor } from '@server/models/application/application' 9import { getServerActor } from '@server/models/application/application'
9import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 10import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models'
10import { ResultList, VideoChannel } from '@shared/models' 11import { VideoChannelsSearchQueryAfterSanitize } from '../../../../shared/models/search'
11import { VideoChannelsSearchQuery } from '../../../../shared/models/search'
12import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' 12import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils'
13import { logger } from '../../../helpers/logger' 13import { logger } from '../../../helpers/logger'
14import { getFormattedObjects } from '../../../helpers/utils' 14import { getFormattedObjects } from '../../../helpers/utils'
@@ -46,8 +46,8 @@ export { searchChannelsRouter }
46// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
47 47
48function searchVideoChannels (req: express.Request, res: express.Response) { 48function 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
70async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: express.Response) { 70async 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
94async function searchVideoChannelsDB (query: VideoChannelsSearchQuery, res: express.Response) { 94async 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(