aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/search
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/search')
-rw-r--r--server/controllers/api/search/search-video-channels.ts19
-rw-r--r--server/controllers/api/search/search-video-playlists.ts19
-rw-r--r--server/controllers/api/search/search-videos.ts24
3 files changed, 31 insertions, 31 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 @@
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'
@@ -7,7 +8,7 @@ import { 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, ResultList, VideoChannel } from '@shared/models' 10import { HttpStatusCode, ResultList, VideoChannel } from '@shared/models'
10import { VideoChannelsSearchQuery } from '../../../../shared/models/search' 11import { VideoChannelsSearchQueryAfterSanitize } from '../../../../shared/models/search'
11import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' 12import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils'
12import { logger } from '../../../helpers/logger' 13import { logger } from '../../../helpers/logger'
13import { getFormattedObjects } from '../../../helpers/utils' 14import { getFormattedObjects } from '../../../helpers/utils'
@@ -45,7 +46,7 @@ export { searchChannelsRouter }
45// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
46 47
47function searchVideoChannels (req: express.Request, res: express.Response) { 48function 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
69async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: express.Response) { 70async 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
93async function searchVideoChannelsDB (query: VideoChannelsSearchQuery, res: express.Response) { 94async 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(
diff --git a/server/controllers/api/search/search-video-playlists.ts b/server/controllers/api/search/search-video-playlists.ts
index bd6a2a564..0a56f19b7 100644
--- a/server/controllers/api/search/search-video-playlists.ts
+++ b/server/controllers/api/search/search-video-playlists.ts
@@ -2,6 +2,7 @@ import * as express from 'express'
2import { sanitizeUrl } from '@server/helpers/core-utils' 2import { sanitizeUrl } from '@server/helpers/core-utils'
3import { isUserAbleToSearchRemoteURI } from '@server/helpers/express-utils' 3import { isUserAbleToSearchRemoteURI } from '@server/helpers/express-utils'
4import { logger } from '@server/helpers/logger' 4import { logger } from '@server/helpers/logger'
5import { pickSearchPlaylistQuery } from '@server/helpers/query'
5import { doJSONRequest } from '@server/helpers/requests' 6import { doJSONRequest } from '@server/helpers/requests'
6import { getFormattedObjects } from '@server/helpers/utils' 7import { getFormattedObjects } from '@server/helpers/utils'
7import { CONFIG } from '@server/initializers/config' 8import { CONFIG } from '@server/initializers/config'
@@ -12,7 +13,7 @@ import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@ser
12import { getServerActor } from '@server/models/application/application' 13import { getServerActor } from '@server/models/application/application'
13import { VideoPlaylistModel } from '@server/models/video/video-playlist' 14import { VideoPlaylistModel } from '@server/models/video/video-playlist'
14import { MVideoPlaylistFullSummary } from '@server/types/models' 15import { MVideoPlaylistFullSummary } from '@server/types/models'
15import { HttpStatusCode, ResultList, VideoPlaylist, VideoPlaylistsSearchQuery } from '@shared/models' 16import { HttpStatusCode, ResultList, VideoPlaylist, VideoPlaylistsSearchQueryAfterSanitize } from '@shared/models'
16import { 17import {
17 asyncMiddleware, 18 asyncMiddleware,
18 openapiOperationDoc, 19 openapiOperationDoc,
@@ -44,7 +45,7 @@ export { searchPlaylistsRouter }
44// --------------------------------------------------------------------------- 45// ---------------------------------------------------------------------------
45 46
46function searchVideoPlaylists (req: express.Request, res: express.Response) { 47function searchVideoPlaylists (req: express.Request, res: express.Response) {
47 const query: VideoPlaylistsSearchQuery = req.query 48 const query = pickSearchPlaylistQuery(req.query)
48 const search = query.search 49 const search = query.search
49 50
50 if (isURISearch(search)) return searchVideoPlaylistsURI(search, res) 51 if (isURISearch(search)) return searchVideoPlaylistsURI(search, res)
@@ -56,7 +57,7 @@ function searchVideoPlaylists (req: express.Request, res: express.Response) {
56 return searchVideoPlaylistsDB(query, res) 57 return searchVideoPlaylistsDB(query, res)
57} 58}
58 59
59async function searchVideoPlaylistsIndex (query: VideoPlaylistsSearchQuery, res: express.Response) { 60async function searchVideoPlaylistsIndex (query: VideoPlaylistsSearchQueryAfterSanitize, res: express.Response) {
60 const result = await buildMutedForSearchIndex(res) 61 const result = await buildMutedForSearchIndex(res)
61 62
62 const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-playlists.index.list.params') 63 const body = await Hooks.wrapObject(Object.assign(query, result), 'filter:api.search.video-playlists.index.list.params')
@@ -80,17 +81,13 @@ async function searchVideoPlaylistsIndex (query: VideoPlaylistsSearchQuery, res:
80 } 81 }
81} 82}
82 83
83async function searchVideoPlaylistsDB (query: VideoPlaylistsSearchQuery, res: express.Response) { 84async function searchVideoPlaylistsDB (query: VideoPlaylistsSearchQueryAfterSanitize, res: express.Response) {
84 const serverActor = await getServerActor() 85 const serverActor = await getServerActor()
85 86
86 const apiOptions = await Hooks.wrapObject({ 87 const apiOptions = await Hooks.wrapObject({
87 followerActorId: serverActor.id, 88 ...query,
88 search: query.search, 89
89 start: query.start, 90 followerActorId: serverActor.id
90 count: query.count,
91 sort: query.sort,
92 host: query.host,
93 uuids: query.uuids
94 }, 'filter:api.search.video-playlists.local.list.params') 91 }, 'filter:api.search.video-playlists.local.list.params')
95 92
96 const resultList = await Hooks.wrapPromiseFun( 93 const resultList = await Hooks.wrapPromiseFun(
diff --git a/server/controllers/api/search/search-videos.ts b/server/controllers/api/search/search-videos.ts
index a4153f3f8..4a6ce0de4 100644
--- a/server/controllers/api/search/search-videos.ts
+++ b/server/controllers/api/search/search-videos.ts
@@ -1,5 +1,6 @@
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 { pickSearchVideoQuery } 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'
@@ -7,7 +8,7 @@ import { getOrCreateAPVideo } from '@server/lib/activitypub/videos'
7import { Hooks } from '@server/lib/plugins/hooks' 8import { Hooks } from '@server/lib/plugins/hooks'
8import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search' 9import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@server/lib/search'
9import { HttpStatusCode, ResultList, Video } from '@shared/models' 10import { HttpStatusCode, ResultList, Video } from '@shared/models'
10import { VideosSearchQuery } from '../../../../shared/models/search' 11import { VideosSearchQueryAfterSanitize } from '../../../../shared/models/search'
11import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils' 12import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils'
12import { logger } from '../../../helpers/logger' 13import { logger } from '../../../helpers/logger'
13import { getFormattedObjects } from '../../../helpers/utils' 14import { getFormattedObjects } from '../../../helpers/utils'
@@ -46,7 +47,7 @@ export { searchVideosRouter }
46// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
47 48
48function searchVideos (req: express.Request, res: express.Response) { 49function searchVideos (req: express.Request, res: express.Response) {
49 const query: VideosSearchQuery = req.query 50 const query = pickSearchVideoQuery(req.query)
50 const search = query.search 51 const search = query.search
51 52
52 if (isURISearch(search)) { 53 if (isURISearch(search)) {
@@ -60,10 +61,10 @@ function searchVideos (req: express.Request, res: express.Response) {
60 return searchVideosDB(query, res) 61 return searchVideosDB(query, res)
61} 62}
62 63
63async function searchVideosIndex (query: VideosSearchQuery, res: express.Response) { 64async function searchVideosIndex (query: VideosSearchQueryAfterSanitize, res: express.Response) {
64 const result = await buildMutedForSearchIndex(res) 65 const result = await buildMutedForSearchIndex(res)
65 66
66 let body: VideosSearchQuery = Object.assign(query, result) 67 let body = { ...query, ...result }
67 68
68 // Use the default instance NSFW policy if not specified 69 // Use the default instance NSFW policy if not specified
69 if (!body.nsfw) { 70 if (!body.nsfw) {
@@ -97,13 +98,18 @@ async function searchVideosIndex (query: VideosSearchQuery, res: express.Respons
97 } 98 }
98} 99}
99 100
100async function searchVideosDB (query: VideosSearchQuery, res: express.Response) { 101async function searchVideosDB (query: VideosSearchQueryAfterSanitize, res: express.Response) {
101 const apiOptions = await Hooks.wrapObject(Object.assign(query, { 102 const apiOptions = await Hooks.wrapObject({
103 ...query,
104
102 includeLocalVideos: true, 105 includeLocalVideos: true,
103 nsfw: buildNSFWFilter(res, query.nsfw),
104 filter: query.filter, 106 filter: query.filter,
105 user: res.locals.oauth ? res.locals.oauth.token.User : undefined 107
106 }), 'filter:api.search.videos.local.list.params') 108 nsfw: buildNSFWFilter(res, query.nsfw),
109 user: res.locals.oauth
110 ? res.locals.oauth.token.User
111 : undefined
112 }, 'filter:api.search.videos.local.list.params')
107 113
108 const resultList = await Hooks.wrapPromiseFun( 114 const resultList = await Hooks.wrapPromiseFun(
109 VideoModel.searchAndPopulateAccountAndServer, 115 VideoModel.searchAndPopulateAccountAndServer,