initial profile implementation!
This commit is contained in:
parent
667b11f2f4
commit
449a11ee55
14 changed files with 212 additions and 57 deletions
|
@ -1,3 +1,7 @@
|
|||
const errors = {
|
||||
AUTHENTICATION_FAILED: "AUTHENTICATION_FAILED",
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /api/v1/instance
|
||||
* @param {string} host - The domain of the target server.
|
||||
|
@ -421,3 +425,26 @@ export async function getUser(host, token, user_id) {
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/accounts/lookup?acct={handle}
|
||||
* @param {string} host - The domain of the target server.
|
||||
* @param {string} token - The application token.
|
||||
* @param {string} handle - The handle of the user to fetch.
|
||||
*/
|
||||
export async function lookupUser(host, token, handle) {
|
||||
let url = `https://${host}/api/v1/accounts/lookup?acct=${handle}`;
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: { "Authorization": token ? `Bearer ${token}` : null }
|
||||
});
|
||||
if (!res.ok) {
|
||||
const json = await res.json();
|
||||
if (json.error = errors.AUTHENTICATION_FAILED)
|
||||
throw new Error("This method requires authentication");
|
||||
}
|
||||
const data = await res.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue