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