fix delegation and stuff

This commit is contained in:
MeowcaTheoRange 2024-03-18 21:39:13 -05:00
parent 3b05a957da
commit ec27da906b

View file

@ -10,6 +10,8 @@ function escapeHtml(unsafe)
.replace(/<\/?object\/?>/g, "");
}
const n=x=>null;
const el_id_user = document.querySelector("#user");
const el_id_instance = document.querySelector("#instance");
const el_id_whoami = document.querySelector("#whoami");
@ -35,18 +37,21 @@ async function verify() {
el_id_instance.value = instance;
if (username.length < 1) return null;
if (instance.length < 1) return null;
let user_req;
try {
user_req = await fetch(`https://${instance}/api/v1/accounts/lookup?acct=${username}`);
} catch (err) {
return null;
}
// webfinger domain delegation
const domain = await fetch(`https://${instance}/.well-known/webfinger?resource=acct:${username}@${instance}`).catch(n);
if (domain == 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();
if (user_req.ok) return {
return {
USER_ID: user_json.id,
INSTANCE: instance
INSTANCE: domain_url
};
else return null;
}
el_id_submitwhoamiFollowers.addEventListener("click", async (e) => {