aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/webfinger.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-14 17:31:26 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad (patch)
treef4191f3c04a5230fcf8ca3d6ca3248643fc4151d /server/helpers/webfinger.ts
parente34c85e527100c0b5c44567bd951e95be41b8d7e (diff)
downloadPeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.gz
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.zst
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.zip
Follow works
Diffstat (limited to 'server/helpers/webfinger.ts')
-rw-r--r--server/helpers/webfinger.ts21
1 files changed, 12 insertions, 9 deletions
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts
index 164ae4951..0155e5f3e 100644
--- a/server/helpers/webfinger.ts
+++ b/server/helpers/webfinger.ts
@@ -12,17 +12,20 @@ const webfinger = new WebFinger({
12 request_timeout: 3000 12 request_timeout: 3000
13}) 13})
14 14
15async function getAccountFromWebfinger (url: string) { 15async function getAccountFromWebfinger (nameWithHost: string) {
16 const webfingerData: WebFingerData = await webfingerLookup(url) 16 const webfingerData: WebFingerData = await webfingerLookup(nameWithHost)
17 17
18 if (Array.isArray(webfingerData.links) === false) return undefined 18 if (Array.isArray(webfingerData.links) === false) throw new Error('WebFinger links is not an array.')
19 19
20 const selfLink = webfingerData.links.find(l => l.rel === 'self') 20 const selfLink = webfingerData.links.find(l => l.rel === 'self')
21 if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) return undefined 21 if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) {
22 throw new Error('Cannot find self link or href is not a valid URL.')
23 }
22 24
23 const { account } = await fetchRemoteAccountAndCreatePod(selfLink.href) 25 const res = await fetchRemoteAccountAndCreatePod(selfLink.href)
26 if (res === undefined) throw new Error('Cannot fetch and create pod of remote account ' + selfLink.href)
24 27
25 return account 28 return res.account
26} 29}
27 30
28// --------------------------------------------------------------------------- 31// ---------------------------------------------------------------------------
@@ -33,12 +36,12 @@ export {
33 36
34// --------------------------------------------------------------------------- 37// ---------------------------------------------------------------------------
35 38
36function webfingerLookup (url: string) { 39function webfingerLookup (nameWithHost: string) {
37 return new Promise<WebFingerData>((res, rej) => { 40 return new Promise<WebFingerData>((res, rej) => {
38 webfinger.lookup(url, (err, p) => { 41 webfinger.lookup(nameWithHost, (err, p) => {
39 if (err) return rej(err) 42 if (err) return rej(err)
40 43
41 return p 44 return res(p.object)
42 }) 45 })
43 }) 46 })
44} 47}