mirror of
https://github.com/AMNatty/Mastodon-Circles.git
synced 2024-11-25 04:27:27 -07:00
Gracefully try host-meta if WebFinger fails
This commit is contained in:
parent
b0e30dbe72
commit
edd46a4a1b
1 changed files with 27 additions and 2 deletions
|
@ -80,11 +80,36 @@ Handle.prototype.webFinger = async function () {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = `https://${this.instance}/.well-known/webfinger?` + new URLSearchParams({
|
const defaultWebfingerUrl = `https://${this.instance}/.well-known/webfinger?` + new URLSearchParams({
|
||||||
resource: `acct:${this}`
|
resource: `acct:${this}`
|
||||||
});
|
});
|
||||||
|
|
||||||
let webFinger = await apiRequest(url);
|
let webFinger = await apiRequest(defaultWebfingerUrl);
|
||||||
|
|
||||||
|
if (!webFinger) {
|
||||||
|
const contentTypeXrd = "application/xrd+xml";
|
||||||
|
const hostMetaUrl = `https://${this.instance}/.well-known/host-meta`;
|
||||||
|
|
||||||
|
console.log(`Fetching :: ${hostMetaUrl}`);
|
||||||
|
let hostMeta = await fetch(hostMetaUrl, {
|
||||||
|
headers: {
|
||||||
|
"Accept": contentTypeXrd
|
||||||
|
},
|
||||||
|
redirect: "follow"
|
||||||
|
}).then(async res => {
|
||||||
|
return new DOMParser()
|
||||||
|
.parseFromString(await res.text(), "text/xml");
|
||||||
|
}).catch(e => {
|
||||||
|
console.error(`Error fetching ${hostMetaUrl}: ${e}`);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
const webfingerTemplate = hostMeta.querySelector("Link[rel='lrdd']")
|
||||||
|
?.getAttribute("template");
|
||||||
|
|
||||||
|
if (webfingerTemplate)
|
||||||
|
webFinger = await apiRequest(webfingerTemplate.replace("{uri}", `acct:${this}`));
|
||||||
|
}
|
||||||
|
|
||||||
if (!webFinger)
|
if (!webFinger)
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue