mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-15 06:27:34 -07:00
add account lookup
This commit is contained in:
parent
0d836df218
commit
f5a9add712
1 changed files with 25 additions and 0 deletions
|
@ -63,6 +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.searchAccount((ctx.query.acct || '').toString(), {
|
||||||
|
resolve: true
|
||||||
|
});
|
||||||
|
ctx.body = data.data[0];
|
||||||
|
if (data.data.length === 0) {
|
||||||
|
ctx.status = 404;
|
||||||
|
ctx.body = {
|
||||||
|
error: "Record not found"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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) => {
|
||||||
|
|
Loading…
Reference in a new issue