From c961939d0fc9cf93c139df657529aef19f4d1983 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Wed, 11 Feb 2026 13:27:51 -0700 Subject: [PATCH] Make it so this endpoint can be used as profile one --- src/index.ts | 4 +++- src/routes/berrydash/account/get.ts | 37 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index f2eae6d..631ae1a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1231,7 +1231,9 @@ app.get('/berrydash/account', context => berryDashAccountGetHandler(context), { tags: ['Berry Dash', 'Accounts'] }, query: t.Object({ - username: t.String() + username: t.Optional(t.String()), + id: t.Optional(t.String()), + exact: t.Optional(t.String()) }), headers: t.Object({ 'x-forwarded-for': t.Optional( diff --git a/src/routes/berrydash/account/get.ts b/src/routes/berrydash/account/get.ts index 038934d..e103ef3 100644 --- a/src/routes/berrydash/account/get.ts +++ b/src/routes/berrydash/account/get.ts @@ -6,6 +6,7 @@ import { } from '../../../lib/util' import { berryDashUserData, users } from '../../../lib/tables' import { eq, sql } from 'drizzle-orm' +import { isDataURI } from 'validator' export const handler = async (context: Context) => { const dbInfo0 = getDatabaseConnection(0) @@ -20,6 +21,21 @@ export const handler = async (context: Context) => { const { connection: connection1, db: db1 } = dbInfo1 const usernameToSearch = context.query.username + const idToSearch = Number(context.query.id ?? '0') + const exactSearch = context.query.exact ?? ''.toLowerCase() == 'true' + if (!usernameToSearch && !(idToSearch > 0 && exactSearch)) { + connection0.end() + connection1.end() + return jsonResponse( + { + success: false, + message: + 'Either `username`, or `id` and `exact=true` params are required', + data: null + }, + 400 + ) + } const userRows = await db0 .select({ @@ -29,10 +45,13 @@ export const handler = async (context: Context) => { }) .from(users) .where( - sql`LOWER(${ - users.username - }) LIKE ${`%${usernameToSearch.toLowerCase()}%`}` + idToSearch > 0 && exactSearch + ? eq(users.id, idToSearch) + : sql`LOWER(${ + users.username + }) LIKE ${`%${usernameToSearch.toLowerCase()}%`}` ) + .limit(idToSearch > 0 && exactSearch ? 1 : 100) .execute() const result = await Promise.all( @@ -76,6 +95,9 @@ export const handler = async (context: Context) => { totalAntiBerries: BigInt( savedata?.gameStore?.totalAntiBerries ?? 0 ).toString(), + totalGoldenBerries: BigInt( + savedata?.gameStore?.totalGoldenBerries ?? 0 + ).toString(), coins: BigInt(savedata?.bird?.customIcon?.balance ?? 0).toString() } return row @@ -85,5 +107,12 @@ export const handler = async (context: Context) => { connection0.end() connection1.end() - return jsonResponse({ success: true, message: null, data: result }, 200) + return jsonResponse( + { + success: true, + message: null, + data: idToSearch > 0 && exactSearch ? result[0] : result + }, + 200 + ) }