From b1d7073217f7d4328a7ec65e246743e8d1d03046 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Tue, 9 Apr 2024 20:13:17 -1000 Subject: [PATCH] Make lookup also work on local users --- server/api/api/v1/accounts/lookup/index.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/server/api/api/v1/accounts/lookup/index.ts b/server/api/api/v1/accounts/lookup/index.ts index cf5e9df8..76cd18cb 100644 --- a/server/api/api/v1/accounts/lookup/index.ts +++ b/server/api/api/v1/accounts/lookup/index.ts @@ -52,8 +52,21 @@ export default apiRoute<{ return errorResponse("Account not found", 404); } - return errorResponse( - "Acct parameter is not of format username@domain.com or @username@domain.com", - 400, - ); + let username = acct; + if (username.startsWith("@")) { + username = username.slice(1); + } + + const account = await client.user.findFirst({ + where: { + username, + }, + include: userRelations, + }); + + if (account) { + return jsonResponse(userToAPI(account)); + } + + return errorResponse(`Account with username ${username} not found"`, 404); });