aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-05-28 10:04:07 +0200
committerChocobozzz <me@florianbigard.com>2019-05-28 10:04:07 +0200
commitc56b774d0594bb33917a9f1080deb2b8814079d7 (patch)
treec1575c62cb42d922e53d8695d41f6c518a7c1e26
parent964298de4e112df0e126aad755c6b077442a2821 (diff)
downloadPeerTube-c56b774d0594bb33917a9f1080deb2b8814079d7.tar.gz
PeerTube-c56b774d0594bb33917a9f1080deb2b8814079d7.tar.zst
PeerTube-c56b774d0594bb33917a9f1080deb2b8814079d7.zip
Fix search with bad webfinger handles
-rw-r--r--server/controllers/api/search.ts14
-rw-r--r--server/helpers/webfinger.ts2
2 files changed, 13 insertions, 3 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index 534305ba6..9a1e30b83 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -59,10 +59,12 @@ function searchVideoChannels (req: express.Request, res: express.Response) {
59 59
60 // Handle strings like @toto@example.com 60 // Handle strings like @toto@example.com
61 if (parts.length === 3 && parts[0].length === 0) parts.shift() 61 if (parts.length === 3 && parts[0].length === 0) parts.shift()
62 const isWebfingerSearch = parts.length === 2 && parts.every(p => p.indexOf(' ') === -1) 62 const isWebfingerSearch = parts.length === 2 && parts.every(p => p && p.indexOf(' ') === -1)
63 63
64 if (isURISearch || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res) 64 if (isURISearch || isWebfingerSearch) return searchVideoChannelURI(search, isWebfingerSearch, res)
65 65
66 // @username -> username to search in DB
67 if (query.search.startsWith('@')) query.search = query.search.replace(/^@/, '')
66 return searchVideoChannelsDB(query, res) 68 return searchVideoChannelsDB(query, res)
67} 69}
68 70
@@ -85,7 +87,15 @@ async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean
85 let videoChannel: VideoChannelModel 87 let videoChannel: VideoChannelModel
86 let uri = search 88 let uri = search
87 89
88 if (isWebfingerSearch) uri = await loadActorUrlOrGetFromWebfinger(search) 90 if (isWebfingerSearch) {
91 try {
92 uri = await loadActorUrlOrGetFromWebfinger(search)
93 } catch (err) {
94 logger.warn('Cannot load actor URL or get from webfinger.', { search, err })
95
96 return res.json({ total: 0, data: [] })
97 }
98 }
89 99
90 if (isUserAbleToSearchRemoteURI(res)) { 100 if (isUserAbleToSearchRemoteURI(res)) {
91 try { 101 try {
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts
index 049808846..d1229e28f 100644
--- a/server/helpers/webfinger.ts
+++ b/server/helpers/webfinger.ts
@@ -19,7 +19,7 @@ async function loadActorUrlOrGetFromWebfinger (uriArg: string) {
19 const [ name, host ] = uri.split('@') 19 const [ name, host ] = uri.split('@')
20 let actor: ActorModel 20 let actor: ActorModel
21 21
22 if (host === WEBSERVER.HOST) { 22 if (!host || host === WEBSERVER.HOST) {
23 actor = await ActorModel.loadLocalByName(name) 23 actor = await ActorModel.loadLocalByName(name)
24 } else { 24 } else {
25 actor = await ActorModel.loadByNameAndHost(name, host) 25 actor = await ActorModel.loadByNameAndHost(name, host)