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-playlists.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-playlists.ts')
-rw-r--r-- | server/controllers/api/search/search-video-playlists.ts | 19 |
1 files changed, 8 insertions, 11 deletions
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' | |||
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' |
@@ -12,7 +13,7 @@ import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@ser | |||
12 | import { getServerActor } from '@server/models/application/application' | 13 | import { getServerActor } from '@server/models/application/application' |
13 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | 14 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' |
14 | import { MVideoPlaylistFullSummary } from '@server/types/models' | 15 | import { MVideoPlaylistFullSummary } from '@server/types/models' |
15 | import { HttpStatusCode, ResultList, VideoPlaylist, VideoPlaylistsSearchQuery } from '@shared/models' | 16 | import { HttpStatusCode, ResultList, VideoPlaylist, VideoPlaylistsSearchQueryAfterSanitize } from '@shared/models' |
16 | import { | 17 | import { |
17 | asyncMiddleware, | 18 | asyncMiddleware, |
18 | openapiOperationDoc, | 19 | openapiOperationDoc, |
@@ -44,7 +45,7 @@ export { searchPlaylistsRouter } | |||
44 | // --------------------------------------------------------------------------- | 45 | // --------------------------------------------------------------------------- |
45 | 46 | ||
46 | function searchVideoPlaylists (req: express.Request, res: express.Response) { | 47 | function 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 | ||
59 | async function searchVideoPlaylistsIndex (query: VideoPlaylistsSearchQuery, res: express.Response) { | 60 | async 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 | ||
83 | async function searchVideoPlaylistsDB (query: VideoPlaylistsSearchQuery, res: express.Response) { | 84 | async 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( |