blob: 9586fa5624b568c1eb2052ef8eec54028bf3f978 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import * as WebFinger from 'webfinger.js'
import { isTestInstance } from './core-utils'
import { isActivityPubUrlValid } from './custom-validators'
import { WebFingerData } from '../../shared'
import { fetchRemoteAccountAndCreatePod } from './activitypub'
const webfinger = new WebFinger({
webfist_fallback: false,
tls_only: isTestInstance(),
uri_fallback: false,
request_timeout: 3000
})
async function getAccountFromWebfinger (url: string) {
const webfingerData: WebFingerData = await webfingerLookup(url)
if (Array.isArray(webfingerData.links) === false) return undefined
const selfLink = webfingerData.links.find(l => l.rel === 'self')
if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) return undefined
const { account } = await fetchRemoteAccountAndCreatePod(selfLink.href)
return account
}
// ---------------------------------------------------------------------------
export {
getAccountFromWebfinger
}
// ---------------------------------------------------------------------------
function webfingerLookup (url: string) {
return new Promise<WebFingerData>((res, rej) => {
webfinger.lookup('nick@silverbucket.net', (err, p) => {
if (err) return rej(err)
return p
})
})
}
|