diff options
author | Chocobozzz <me@florianbigard.com> | 2019-05-28 10:04:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-05-28 10:16:59 +0200 |
commit | cce1b3dfd386c77a02f2b4f18f60bd916a60a2d3 (patch) | |
tree | 68b0e799ef6344c6737360672a79e199d9a0381f /server/controllers/api/search.ts | |
parent | 4d09cfba7820544e72f04bf83c680bc24b775358 (diff) | |
download | PeerTube-cce1b3dfd386c77a02f2b4f18f60bd916a60a2d3.tar.gz PeerTube-cce1b3dfd386c77a02f2b4f18f60bd916a60a2d3.tar.zst PeerTube-cce1b3dfd386c77a02f2b4f18f60bd916a60a2d3.zip |
Fix search with bad webfinger handles
Diffstat (limited to 'server/controllers/api/search.ts')
-rw-r--r-- | server/controllers/api/search.ts | 14 |
1 files changed, 12 insertions, 2 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 { |