1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Follow works

This commit is contained in:
Chocobozzz 2017-11-14 17:31:26 +01:00
parent e34c85e527
commit 350e31d6b6
No known key found for this signature in database
GPG key ID: 583A612D890159BE
39 changed files with 431 additions and 169 deletions

View file

@ -12,17 +12,20 @@ const webfinger = new WebFinger({
request_timeout: 3000
})
async function getAccountFromWebfinger (url: string) {
const webfingerData: WebFingerData = await webfingerLookup(url)
async function getAccountFromWebfinger (nameWithHost: string) {
const webfingerData: WebFingerData = await webfingerLookup(nameWithHost)
if (Array.isArray(webfingerData.links) === false) return undefined
if (Array.isArray(webfingerData.links) === false) throw new Error('WebFinger links is not an array.')
const selfLink = webfingerData.links.find(l => l.rel === 'self')
if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) return undefined
if (selfLink === undefined || isActivityPubUrlValid(selfLink.href) === false) {
throw new Error('Cannot find self link or href is not a valid URL.')
}
const { account } = await fetchRemoteAccountAndCreatePod(selfLink.href)
const res = await fetchRemoteAccountAndCreatePod(selfLink.href)
if (res === undefined) throw new Error('Cannot fetch and create pod of remote account ' + selfLink.href)
return account
return res.account
}
// ---------------------------------------------------------------------------
@ -33,12 +36,12 @@ export {
// ---------------------------------------------------------------------------
function webfingerLookup (url: string) {
function webfingerLookup (nameWithHost: string) {
return new Promise<WebFingerData>((res, rej) => {
webfinger.lookup(url, (err, p) => {
webfinger.lookup(nameWithHost, (err, p) => {
if (err) return rej(err)
return p
return res(p.object)
})
})
}