diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-09 17:51:58 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | e4f97babf701481b55cc10fb3448feab5f97c867 (patch) | |
tree | af37402a594dc5ff09f71ecb0687e8cfe4cdb471 /server/helpers/webfinger.ts | |
parent | 343ad675f2a26c15b86150a9a3552e619d5d44f4 (diff) | |
download | PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.gz PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.zst PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.zip |
Begin activitypub
Diffstat (limited to 'server/helpers/webfinger.ts')
-rw-r--r-- | server/helpers/webfinger.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts new file mode 100644 index 000000000..9586fa562 --- /dev/null +++ b/server/helpers/webfinger.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | import * as WebFinger from 'webfinger.js' | ||
2 | |||
3 | import { isTestInstance } from './core-utils' | ||
4 | import { isActivityPubUrlValid } from './custom-validators' | ||
5 | import { WebFingerData } from '../../shared' | ||
6 | import { fetchRemoteAccountAndCreatePod } from './activitypub' | ||
7 | |||
8 | const webfinger = new WebFinger({ | ||
9 | webfist_fallback: false, | ||
10 | tls_only: isTestInstance(), | ||
11 | uri_fallback: false, | ||
12 | request_timeout: 3000 | ||
13 | }) | ||
14 | |||
15 | async function getAccountFromWebfinger (url: string) { | ||
16 | const webfingerData: WebFingerData = await webfingerLookup(url) | ||
17 | |||
18 | if (Array.isArray(webfingerData.links) === false) return undefined | ||
19 | |||
20 | const selfLink = webfingerData.links.find(l => l.rel === 'self') | ||
21 | if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) return undefined | ||
22 | |||
23 | const { account } = await fetchRemoteAccountAndCreatePod(selfLink.href) | ||
24 | |||
25 | return account | ||
26 | } | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | export { | ||
31 | getAccountFromWebfinger | ||
32 | } | ||
33 | |||
34 | // --------------------------------------------------------------------------- | ||
35 | |||
36 | function webfingerLookup (url: string) { | ||
37 | return new Promise<WebFingerData>((res, rej) => { | ||
38 | webfinger.lookup('nick@silverbucket.net', (err, p) => { | ||
39 | if (err) return rej(err) | ||
40 | |||
41 | return p | ||
42 | }) | ||
43 | }) | ||
44 | } | ||