fix delegation and stuff
This commit is contained in:
parent
3b05a957da
commit
ec27da906b
1 changed files with 14 additions and 9 deletions
|
@ -10,6 +10,8 @@ function escapeHtml(unsafe)
|
||||||
.replace(/<\/?object\/?>/g, "");
|
.replace(/<\/?object\/?>/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const n=x=>null;
|
||||||
|
|
||||||
const el_id_user = document.querySelector("#user");
|
const el_id_user = document.querySelector("#user");
|
||||||
const el_id_instance = document.querySelector("#instance");
|
const el_id_instance = document.querySelector("#instance");
|
||||||
const el_id_whoami = document.querySelector("#whoami");
|
const el_id_whoami = document.querySelector("#whoami");
|
||||||
|
@ -35,18 +37,21 @@ async function verify() {
|
||||||
el_id_instance.value = instance;
|
el_id_instance.value = instance;
|
||||||
if (username.length < 1) return null;
|
if (username.length < 1) return null;
|
||||||
if (instance.length < 1) return null;
|
if (instance.length < 1) return null;
|
||||||
let user_req;
|
|
||||||
try {
|
// webfinger domain delegation
|
||||||
user_req = await fetch(`https://${instance}/api/v1/accounts/lookup?acct=${username}`);
|
const domain = await fetch(`https://${instance}/.well-known/webfinger?resource=acct:${username}@${instance}`).catch(n);
|
||||||
} catch (err) {
|
if (domain == null) return null;
|
||||||
return null;
|
const domain_json = (await domain.json());
|
||||||
}
|
const domain_url = new URL(domain_json.links.find(x=>x.type=="application/activity+json").href).hostname;
|
||||||
|
|
||||||
|
const user_req = await fetch(`https://${domain_url}/api/v1/accounts/lookup?acct=${username}`).catch(n);
|
||||||
|
if (user_req == null) return null;
|
||||||
const user_json = await user_req.json();
|
const user_json = await user_req.json();
|
||||||
if (user_req.ok) return {
|
|
||||||
|
return {
|
||||||
USER_ID: user_json.id,
|
USER_ID: user_json.id,
|
||||||
INSTANCE: instance
|
INSTANCE: domain_url
|
||||||
};
|
};
|
||||||
else return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
el_id_submitwhoamiFollowers.addEventListener("click", async (e) => {
|
el_id_submitwhoamiFollowers.addEventListener("click", async (e) => {
|
||||||
|
|
Loading…
Reference in a new issue