aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/search
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-20 15:01:17 +0200
committerChocobozzz <me@florianbigard.com>2021-10-20 15:26:38 +0200
commit400043b1be38cdd7bc39462fa6a545eea0bea03e (patch)
tree68f447d00e06f80bbe84bf38dac30005e66cf2e4 /server/controllers/api/search
parentebe9b6b3f32d8432980854a51d28a8fb88fe62e5 (diff)
downloadPeerTube-400043b1be38cdd7bc39462fa6a545eea0bea03e.tar.gz
PeerTube-400043b1be38cdd7bc39462fa6a545eea0bea03e.tar.zst
PeerTube-400043b1be38cdd7bc39462fa6a545eea0bea03e.zip
Add ability to search by URL with query params
Diffstat (limited to 'server/controllers/api/search')
-rw-r--r--server/controllers/api/search/search-video-channels.ts3
-rw-r--r--server/controllers/api/search/search-video-playlists.ts3
-rw-r--r--server/controllers/api/search/search-videos.ts3
-rw-r--r--server/controllers/api/search/shared/index.ts1
-rw-r--r--server/controllers/api/search/shared/utils.ts16
5 files changed, 23 insertions, 3 deletions
diff --git a/server/controllers/api/search/search-video-channels.ts b/server/controllers/api/search/search-video-channels.ts
index 089feed65..c9e81bffa 100644
--- a/server/controllers/api/search/search-video-channels.ts
+++ b/server/controllers/api/search/search-video-channels.ts
@@ -25,6 +25,7 @@ import {
25} from '../../../middlewares' 25} from '../../../middlewares'
26import { VideoChannelModel } from '../../../models/video/video-channel' 26import { VideoChannelModel } from '../../../models/video/video-channel'
27import { MChannelAccountDefault } from '../../../types/models' 27import { MChannelAccountDefault } from '../../../types/models'
28import { searchLocalUrl } from './shared'
28 29
29const searchChannelsRouter = express.Router() 30const searchChannelsRouter = express.Router()
30 31
@@ -131,7 +132,7 @@ async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean
131 logger.info('Cannot search remote video channel %s.', uri, { err }) 132 logger.info('Cannot search remote video channel %s.', uri, { err })
132 } 133 }
133 } else { 134 } else {
134 videoChannel = await VideoChannelModel.loadByUrlAndPopulateAccount(sanitizeLocalUrl(uri)) 135 videoChannel = await searchLocalUrl(sanitizeLocalUrl(uri), url => VideoChannelModel.loadByUrlAndPopulateAccount(url))
135 } 136 }
136 137
137 return res.json({ 138 return res.json({
diff --git a/server/controllers/api/search/search-video-playlists.ts b/server/controllers/api/search/search-video-playlists.ts
index b28f11c79..61a11c74a 100644
--- a/server/controllers/api/search/search-video-playlists.ts
+++ b/server/controllers/api/search/search-video-playlists.ts
@@ -24,6 +24,7 @@ import {
24 videoPlaylistsListSearchValidator, 24 videoPlaylistsListSearchValidator,
25 videoPlaylistsSearchSortValidator 25 videoPlaylistsSearchSortValidator
26} from '../../../middlewares' 26} from '../../../middlewares'
27import { searchLocalUrl } from './shared'
27 28
28const searchPlaylistsRouter = express.Router() 29const searchPlaylistsRouter = express.Router()
29 30
@@ -109,7 +110,7 @@ async function searchVideoPlaylistsURI (search: string, res: express.Response) {
109 logger.info('Cannot search remote video playlist %s.', search, { err }) 110 logger.info('Cannot search remote video playlist %s.', search, { err })
110 } 111 }
111 } else { 112 } else {
112 videoPlaylist = await VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(sanitizeLocalUrl(search)) 113 videoPlaylist = await searchLocalUrl(sanitizeLocalUrl(search), url => VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(url))
113 } 114 }
114 115
115 return res.json({ 116 return res.json({
diff --git a/server/controllers/api/search/search-videos.ts b/server/controllers/api/search/search-videos.ts
index eb7ce0841..90946cb74 100644
--- a/server/controllers/api/search/search-videos.ts
+++ b/server/controllers/api/search/search-videos.ts
@@ -25,6 +25,7 @@ import {
25} from '../../../middlewares' 25} from '../../../middlewares'
26import { VideoModel } from '../../../models/video/video' 26import { VideoModel } from '../../../models/video/video'
27import { MVideoAccountLightBlacklistAllFiles } from '../../../types/models' 27import { MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
28import { searchLocalUrl } from './shared'
28 29
29const searchVideosRouter = express.Router() 30const searchVideosRouter = express.Router()
30 31
@@ -141,7 +142,7 @@ async function searchVideoURI (url: string, res: express.Response) {
141 logger.info('Cannot search remote video %s.', url, { err }) 142 logger.info('Cannot search remote video %s.', url, { err })
142 } 143 }
143 } else { 144 } else {
144 video = await VideoModel.loadByUrlAndPopulateAccount(sanitizeLocalUrl(url)) 145 video = await searchLocalUrl(sanitizeLocalUrl(url), url => VideoModel.loadByUrlAndPopulateAccount(url))
145 } 146 }
146 147
147 return res.json({ 148 return res.json({
diff --git a/server/controllers/api/search/shared/index.ts b/server/controllers/api/search/shared/index.ts
new file mode 100644
index 000000000..9c56149ef
--- /dev/null
+++ b/server/controllers/api/search/shared/index.ts
@@ -0,0 +1 @@
export * from './utils'
diff --git a/server/controllers/api/search/shared/utils.ts b/server/controllers/api/search/shared/utils.ts
new file mode 100644
index 000000000..e02e84f31
--- /dev/null
+++ b/server/controllers/api/search/shared/utils.ts
@@ -0,0 +1,16 @@
1async function searchLocalUrl <T> (url: string, finder: (url: string) => Promise<T>) {
2 const data = await finder(url)
3 if (data) return data
4
5 return finder(removeQueryParams(url))
6}
7
8export {
9 searchLocalUrl
10}
11
12// ---------------------------------------------------------------------------
13
14function removeQueryParams (url: string) {
15 return url.split('?').shift()
16}