mirror of
https://github.com/AMNatty/Mastodon-Circles.git
synced 2024-11-25 04:27:27 -07:00
Implement delegated domain check
This commit is contained in:
parent
73bb66a3f1
commit
5e1ef08548
1 changed files with 18 additions and 1 deletions
|
@ -21,6 +21,7 @@ async function apiRequest(url, options = null)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
|
* handle: string,
|
||||||
* name: string,
|
* name: string,
|
||||||
* instance: string,
|
* instance: string,
|
||||||
* }} Handle
|
* }} Handle
|
||||||
|
@ -189,7 +190,7 @@ class MastodonApiClient extends ApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserIdFromHandle(handle) {
|
async getUserIdFromHandle(handle) {
|
||||||
const url = `https://${this._instance}/api/v1/accounts/lookup?acct=${handle.name}@${handle.instance}`;
|
const url = `https://${this._instance}/api/v1/accounts/lookup?acct=${handle.handle}`;
|
||||||
const response = await apiRequest(url, null);
|
const response = await apiRequest(url, null);
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
|
@ -547,11 +548,25 @@ function parseHandle(fediHandle, fallbackInstance = "") {
|
||||||
const [name, instance] = fediHandle.split("@", 2);
|
const [name, instance] = fediHandle.split("@", 2);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
handle: fediHandle,
|
||||||
name: name,
|
name: name,
|
||||||
instance: instance || fallbackInstance,
|
instance: instance || fallbackInstance,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef @param {Handle} handle
|
||||||
|
* @returns {Promise<string>} instance
|
||||||
|
*/
|
||||||
|
async function getDelegateInstance(handle) {
|
||||||
|
// We're checking webfinger to see which URL is for the user,
|
||||||
|
// since that may be on a different domain than the webfinger request
|
||||||
|
const response = await apiRequest(`https://${handle.instance}/.well-known/webfinger?resource=acct:${handle.handle}`)
|
||||||
|
const selfLink = response.links.find(link => link.rel == 'self')
|
||||||
|
const url = new URL(selfLink.href)
|
||||||
|
return url.hostname;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {FediUser & {conStrength: number}} RatedUser
|
* @typedef {FediUser & {conStrength: number}} RatedUser
|
||||||
*/
|
*/
|
||||||
|
@ -566,6 +581,8 @@ async function circleMain() {
|
||||||
let fediHandle = document.getElementById("txt_mastodon_handle");
|
let fediHandle = document.getElementById("txt_mastodon_handle");
|
||||||
const selfUser = parseHandle(fediHandle.value);
|
const selfUser = parseHandle(fediHandle.value);
|
||||||
|
|
||||||
|
selfUser.instance = await getDelegateInstance(selfUser)
|
||||||
|
|
||||||
let form = document.getElementById("generateForm");
|
let form = document.getElementById("generateForm");
|
||||||
let backend = form.backend;
|
let backend = form.backend;
|
||||||
for (const radio of backend) {
|
for (const radio of backend) {
|
||||||
|
|
Loading…
Reference in a new issue