From 631355c2c8dc4c0ad4188b8e1fc175f20c65661e Mon Sep 17 00:00:00 2001 From: cutestnekoaqua Date: Sun, 12 Feb 2023 00:10:10 +0100 Subject: [PATCH] add account lookup --- .../server/api/mastodon/endpoints/account.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/backend/src/server/api/mastodon/endpoints/account.ts b/packages/backend/src/server/api/mastodon/endpoints/account.ts index 58de9ad178..82c721ef47 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/account.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/account.ts @@ -63,6 +63,31 @@ export function apiAccountMastodon(router: Router): void { 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 } }>( "/v1/accounts/:id", async (ctx) => {