aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-24 11:04:02 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commitf5b0af50c85e2f8b6b2b054ac1f47123cacbe08d (patch)
tree1b2f8a578b2d35138ac326d65674a9c9d740e8c9 /server/controllers
parentaa55a4da422330fe2816f1764b64f6607a0ca4aa (diff)
downloadPeerTube-f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d.tar.gz
PeerTube-f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d.tar.zst
PeerTube-f5b0af50c85e2f8b6b2b054ac1f47123cacbe08d.zip
Search video channel handle/uri
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/search.ts25
1 files changed, 14 insertions, 11 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index 87aa5d76f..959d79855 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -41,7 +41,6 @@ searchRouter.get('/video-channels',
41 videoChannelsSearchSortValidator, 41 videoChannelsSearchSortValidator,
42 setDefaultSearchSort, 42 setDefaultSearchSort,
43 optionalAuthenticate, 43 optionalAuthenticate,
44 commonVideosFiltersValidator,
45 videoChannelsSearchValidator, 44 videoChannelsSearchValidator,
46 asyncMiddleware(searchVideoChannels) 45 asyncMiddleware(searchVideoChannels)
47) 46)
@@ -59,9 +58,9 @@ function searchVideoChannels (req: express.Request, res: express.Response) {
59 const isURISearch = search.startsWith('http://') || search.startsWith('https://') 58 const isURISearch = search.startsWith('http://') || search.startsWith('https://')
60 59
61 const parts = search.split('@') 60 const parts = search.split('@')
62 const isHandleSearch = parts.length === 2 && parts.every(p => p.indexOf(' ') === -1) 61 const isWebfingerSearch = parts.length === 2 && parts.every(p => p.indexOf(' ') === -1)
63 62
64 if (isURISearch || isHandleSearch) return searchVideoChannelURI(search, isHandleSearch, res) 63 if (isURISearch || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res)
65 64
66 return searchVideoChannelsDB(query, res) 65 return searchVideoChannelsDB(query, res)
67} 66}
@@ -81,17 +80,21 @@ async function searchVideoChannelsDB (query: VideoChannelsSearchQuery, res: expr
81 return res.json(getFormattedObjects(resultList.data, resultList.total)) 80 return res.json(getFormattedObjects(resultList.data, resultList.total))
82} 81}
83 82
84async function searchVideoChannelURI (search: string, isHandleSearch: boolean, res: express.Response) { 83async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean, res: express.Response) {
85 let videoChannel: VideoChannelModel 84 let videoChannel: VideoChannelModel
85 let uri = search
86 86
87 if (isUserAbleToSearchRemoteURI(res)) { 87 if (isWebfingerSearch) uri = await loadActorUrlOrGetFromWebfinger(search)
88 let uri = search
89 if (isHandleSearch) uri = await loadActorUrlOrGetFromWebfinger(search)
90 88
91 const actor = await getOrCreateActorAndServerAndModel(uri) 89 if (isUserAbleToSearchRemoteURI(res)) {
92 videoChannel = actor.VideoChannel 90 try {
91 const actor = await getOrCreateActorAndServerAndModel(uri)
92 videoChannel = actor.VideoChannel
93 } catch (err) {
94 logger.info('Cannot search remote video channel %s.', uri, { err })
95 }
93 } else { 96 } else {
94 videoChannel = await VideoChannelModel.loadByUrlAndPopulateAccount(search) 97 videoChannel = await VideoChannelModel.loadByUrlAndPopulateAccount(uri)
95 } 98 }
96 99
97 return res.json({ 100 return res.json({
@@ -138,7 +141,7 @@ async function searchVideoURI (url: string, res: express.Response) {
138 const result = await getOrCreateVideoAndAccountAndChannel(url, syncParam) 141 const result = await getOrCreateVideoAndAccountAndChannel(url, syncParam)
139 video = result ? result.video : undefined 142 video = result ? result.video : undefined
140 } catch (err) { 143 } catch (err) {
141 logger.info('Cannot search remote video %s.', url) 144 logger.info('Cannot search remote video %s.', url, { err })
142 } 145 }
143 } else { 146 } else {
144 video = await VideoModel.loadByUrlAndPopulateAccount(url) 147 video = await VideoModel.loadByUrlAndPopulateAccount(url)