This commit is contained in:
cutestnekoaqua 2023-02-12 00:29:52 +01:00
parent 63cd831cf6
commit b862402ce9
No known key found for this signature in database
GPG Key ID: 6BF0964A5069C1E0
1 changed files with 18 additions and 7 deletions

View File

@ -63,20 +63,31 @@ export function apiAccountMastodon(router: Router): void {
ctx.body = e.response.data; ctx.body = e.response.data;
} }
}); });
router.get(
"/v1/accounts/lookup",
async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getAccount(( || '').toString());
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.get<{ Params: { id: string } }>( router.get<{ Params: { id: string } }>(
"/v1/accounts/:id", "/v1/accounts/:id",
async (ctx) => { async (ctx) => {
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization; const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens); const client = getClient(BASE_URL, accessTokens);
let req_user = ctx.query.acct;
if (!req_user) {
req_user = ctx.params.id;
} else {
req_user = req_user.toString();
}
try { try {
const data = await client.getAccount(req_user); const data = await client.getAccount(ctx.params.id);
ctx.body = data.data; ctx.body = data.data;
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);