add duid endpoint

This commit is contained in:
Devin Zuczek
2026-07-13 17:35:35 -04:00
parent 06c9f8f409
commit 08f25fb584
3 changed files with 68 additions and 0 deletions
+15
View File
@@ -55,6 +55,12 @@ export interface Account {
phone?: string
/** Set via PUT /account/me/bio; read back via GET /account/:id/bio. */
bio?: string
/**
* Hardware/install id the client last reported (POST /api/PlayerReporting/v1/deviceId).
* The client rotates it — it posts the id it believes we hold plus the new one —
* so this is simply the most recent value it told us about, not a proven identity.
*/
deviceId?: string
/** Remaining username changes; decremented by PUT /account/me/username. */
availableUsernameChanges?: number
/**
@@ -211,6 +217,15 @@ export async function setLastLoginTime(db: D1Database, id: number, time: string)
.run()
}
/** Record the device id the client last reported. False when no such account exists. */
export async function setDeviceId(db: D1Database, id: number, deviceId: string): Promise<boolean> {
const { meta } = await db
.prepare("UPDATE account SET data = json_set(data, '$.deviceId', ?2) WHERE account_id = ?1")
.bind(id, deviceId)
.run()
return meta.changes > 0
}
/** Look up multiple accounts by AccountId (order not guaranteed). */
export async function getAccountsByIds(db: D1Database, ids: number[]): Promise<Account[]> {
if (ids.length === 0) return []