mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 22:51:30 -07:00
update some naming conventions
This commit is contained in:
@@ -3,7 +3,7 @@ import type { SharedHonoEnv, SharedHonoVariables } from '@repo/hono-helpers/src/
|
||||
|
||||
export type Env = SharedHonoEnv & {
|
||||
/** Per-player settings store. Key `player:<id>` → JSON map of `{ key: value }`. */
|
||||
PLAYER_SETTINGS: KVNamespace
|
||||
RECFLARE_PLAYER_SETTINGS: KVNamespace
|
||||
}
|
||||
|
||||
/** Variables can be extended */
|
||||
|
||||
@@ -89,10 +89,10 @@ const app = new Hono<App>()
|
||||
if (id === null) return unauthorized(c)
|
||||
|
||||
const kvKey = `player:${id}`
|
||||
let stored = await c.env.PLAYER_SETTINGS.get<Record<string, string>>(kvKey, 'json')
|
||||
let stored = await c.env.RECFLARE_PLAYER_SETTINGS.get<Record<string, string>>(kvKey, 'json')
|
||||
if (!stored || Object.keys(stored).length === 0) {
|
||||
stored = Object.fromEntries(DEFAULT_SETTINGS.map((s) => [s.Key, s.Value]))
|
||||
await c.env.PLAYER_SETTINGS.put(kvKey, JSON.stringify(stored))
|
||||
await c.env.RECFLARE_PLAYER_SETTINGS.put(kvKey, JSON.stringify(stored))
|
||||
}
|
||||
|
||||
return c.json(Object.entries(stored).map(([Key, Value]) => ({ PlayerId: id, Key, Value })))
|
||||
@@ -109,11 +109,11 @@ const app = new Hono<App>()
|
||||
if (incoming.length === 0) return c.body(null, 200)
|
||||
|
||||
const kvKey = `player:${id}`
|
||||
const existing = await c.env.PLAYER_SETTINGS.get<Record<string, string>>(kvKey, 'json')
|
||||
const existing = await c.env.RECFLARE_PLAYER_SETTINGS.get<Record<string, string>>(kvKey, 'json')
|
||||
const merged: Record<string, string> = { ...existing }
|
||||
for (const { key, value } of incoming) merged[key] = value
|
||||
|
||||
await c.env.PLAYER_SETTINGS.put(kvKey, JSON.stringify(merged))
|
||||
await c.env.RECFLARE_PLAYER_SETTINGS.put(kvKey, JSON.stringify(merged))
|
||||
return c.body(null, 200)
|
||||
})
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('playersettings endpoints', () => {
|
||||
expect(settings.find((s) => s.Key === 'PlayerSessionCount')?.Value).toBe('13')
|
||||
|
||||
// Defaults were persisted to KV.
|
||||
const stored = await env.PLAYER_SETTINGS.get<Record<string, string>>('player:100', 'json')
|
||||
const stored = await env.RECFLARE_PLAYER_SETTINGS.get<Record<string, string>>('player:100', 'json')
|
||||
expect(stored?.['Recroom.OOBE']).toBe('77')
|
||||
})
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('playersettings endpoints', () => {
|
||||
)
|
||||
expect(res.status).toBe(200)
|
||||
|
||||
const stored = await env.PLAYER_SETTINGS.get<Record<string, string>>('player:7', 'json')
|
||||
const stored = await env.RECFLARE_PLAYER_SETTINGS.get<Record<string, string>>('player:7', 'json')
|
||||
expect(stored).toEqual({ PlayerSessionCount: '1' })
|
||||
})
|
||||
|
||||
@@ -111,7 +111,7 @@ describe('playersettings endpoints', () => {
|
||||
putForm({ key: 'B', value: '2' }, await bearer('8'))
|
||||
)
|
||||
|
||||
const stored = await env.PLAYER_SETTINGS.get<Record<string, string>>('player:8', 'json')
|
||||
const stored = await env.RECFLARE_PLAYER_SETTINGS.get<Record<string, string>>('player:8', 'json')
|
||||
expect(stored).toEqual({ A: '1', B: '2' })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user