Make get account endpoint have the same info from profile endpoint. Need to add ?id= and ?exact= though
This commit is contained in:
@@ -961,8 +961,10 @@ app.get(
|
|||||||
app.get('/berrydash/profile', context => berrydashProfileGetHandler(context), {
|
app.get('/berrydash/profile', context => berrydashProfileGetHandler(context), {
|
||||||
detail: {
|
detail: {
|
||||||
description:
|
description:
|
||||||
"The endpoint for getting a user's profile." + intNotStr('userId'),
|
"The endpoint for getting a user's profile.\n\n**Do not use this endpoint. It is the same as `/api/berrydash/account?id=(id)&exact=true` and will be removed on March 19th 2026.**" +
|
||||||
tags: ['Berry Dash', 'Profiles']
|
intNotStr('userId'),
|
||||||
|
tags: ['Berry Dash', 'Profiles'],
|
||||||
|
deprecated: true
|
||||||
},
|
},
|
||||||
query: t.Object({
|
query: t.Object({
|
||||||
userId: t.String()
|
userId: t.String()
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import { Context } from 'elysia'
|
import { Context } from 'elysia'
|
||||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
import {
|
||||||
|
genTimestamp,
|
||||||
|
getDatabaseConnection,
|
||||||
|
jsonResponse
|
||||||
|
} from '../../../lib/util'
|
||||||
import { berryDashUserData, users } from '../../../lib/tables'
|
import { berryDashUserData, users } from '../../../lib/tables'
|
||||||
import { eq, sql } from 'drizzle-orm'
|
import { eq, sql } from 'drizzle-orm'
|
||||||
|
import { calculateXP } from '../../../lib/bd'
|
||||||
|
|
||||||
export const handler = async (context: Context) => {
|
export const handler = async (context: Context) => {
|
||||||
const dbInfo0 = getDatabaseConnection(0)
|
const dbInfo0 = getDatabaseConnection(0)
|
||||||
@@ -18,7 +23,11 @@ export const handler = async (context: Context) => {
|
|||||||
const usernameToSearch = context.query.username
|
const usernameToSearch = context.query.username
|
||||||
|
|
||||||
const userRows = await db0
|
const userRows = await db0
|
||||||
.select({ id: users.id, username: users.username })
|
.select({
|
||||||
|
id: users.id,
|
||||||
|
username: users.username,
|
||||||
|
registerTime: users.registerTime
|
||||||
|
})
|
||||||
.from(users)
|
.from(users)
|
||||||
.where(
|
.where(
|
||||||
sql`LOWER(${
|
sql`LOWER(${
|
||||||
@@ -35,32 +44,48 @@ export const handler = async (context: Context) => {
|
|||||||
.where(eq(berryDashUserData.id, row.id))
|
.where(eq(berryDashUserData.id, row.id))
|
||||||
.execute()
|
.execute()
|
||||||
const savedata = JSON.parse(userData[0].saveData)
|
const savedata = JSON.parse(userData[0].saveData)
|
||||||
|
row.memberFor = genTimestamp(row.registerTime, 2)
|
||||||
|
delete row.registerTime
|
||||||
row.icon = savedata?.bird?.icon ?? 1
|
row.icon = savedata?.bird?.icon ?? 1
|
||||||
row.overlay = savedata?.bird?.overlay ?? 0
|
row.overlay = savedata?.bird?.overlay ?? 0
|
||||||
row.birdColor = savedata?.settings?.colors?.icon ?? [255, 255, 255]
|
row.birdColor = savedata?.settings?.colors?.icon ?? [255, 255, 255]
|
||||||
row.overlayColor = savedata?.settings?.colors?.overlay ?? [255, 255, 255]
|
row.overlayColor = savedata?.settings?.colors?.overlay ?? [255, 255, 255]
|
||||||
row.customIcon = savedata?.bird?.customIcon?.selected ?? null
|
row.customIcon = savedata?.bird?.customIcon?.selected ?? null
|
||||||
row.stats = {
|
row.stats = {
|
||||||
highScore: parseInt(savedata?.gameStore?.highScore ?? 0),
|
highScore: BigInt(savedata?.gameStore?.highScore ?? 0).toString(),
|
||||||
totalNormalBerries: parseInt(
|
totalNormalBerries: BigInt(
|
||||||
savedata?.gameStore?.totalNormalBerries ?? 0
|
savedata?.gameStore?.totalNormalBerries ?? 0
|
||||||
),
|
).toString(),
|
||||||
totalPoisonBerries: parseInt(
|
totalPoisonBerries: BigInt(
|
||||||
savedata?.gameStore?.totalPoisonBerries ?? 0
|
savedata?.gameStore?.totalPoisonBerries ?? 0
|
||||||
),
|
).toString(),
|
||||||
totalSlowBerries: parseInt(savedata?.gameStore?.totalSlowBerries ?? 0),
|
totalSlowBerries: BigInt(
|
||||||
totalUltraBerries: parseInt(
|
savedata?.gameStore?.totalSlowBerries ?? 0
|
||||||
|
).toString(),
|
||||||
|
totalUltraBerries: BigInt(
|
||||||
savedata?.gameStore?.totalUltraBerries ?? 0
|
savedata?.gameStore?.totalUltraBerries ?? 0
|
||||||
),
|
).toString(),
|
||||||
totalSpeedyBerries: parseInt(
|
totalSpeedyBerries: BigInt(
|
||||||
savedata?.gameStore?.totalSpeedyBerries ?? 0
|
savedata?.gameStore?.totalSpeedyBerries ?? 0
|
||||||
),
|
).toString(),
|
||||||
totalCoinBerries: parseInt(savedata?.gameStore?.totalCoinBerries ?? 0),
|
totalCoinBerries: BigInt(
|
||||||
totalRandomBerries: parseInt(
|
savedata?.gameStore?.totalCoinBerries ?? 0
|
||||||
|
).toString(),
|
||||||
|
totalRandomBerries: BigInt(
|
||||||
savedata?.gameStore?.totalRandomBerries ?? 0
|
savedata?.gameStore?.totalRandomBerries ?? 0
|
||||||
),
|
).toString(),
|
||||||
totalAntiBerries: parseInt(savedata?.gameStore?.totalAntiBerries ?? 0),
|
totalAntiBerries: BigInt(
|
||||||
coins: savedata?.bird?.customIcon?.balance ?? 0
|
savedata?.gameStore?.totalAntiBerries ?? 0
|
||||||
|
).toString(),
|
||||||
|
xp: calculateXP(
|
||||||
|
BigInt(savedata?.gameStore?.totalNormalBerries ?? 0),
|
||||||
|
BigInt(savedata?.gameStore?.totalPoisonBerries ?? 0),
|
||||||
|
BigInt(savedata?.gameStore?.totalSlowBerries ?? 0),
|
||||||
|
BigInt(savedata?.gameStore?.totalUltraBerries ?? 0),
|
||||||
|
BigInt(savedata?.gameStore?.totalSpeedyBerries ?? 0),
|
||||||
|
BigInt(savedata?.gameStore?.totalCoinBerries ?? 0)
|
||||||
|
).toString(),
|
||||||
|
coins: BigInt(savedata?.bird?.customIcon?.balance ?? 0).toString()
|
||||||
}
|
}
|
||||||
return row
|
return row
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user