mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
update some naming conventions
This commit is contained in:
@@ -9,7 +9,7 @@ Player-settings worker served on the `playersettings` subdomain.
|
||||
- `PUT /playersettings` — `[Authorize]`. Accepts a form-urlencoded
|
||||
`key=…&value=…` (or a JSON `{key,value}` / array) and **upserts** it into the
|
||||
player's settings, keyed by the `sub` claim of the Bearer JWT. Returns `200`.
|
||||
Persisted in Workers KV (`PLAYER_SETTINGS`, key `player:<id>`).
|
||||
Persisted in Workers KV (`RECFLARE_PLAYER_SETTINGS`, key `player:<id>`).
|
||||
|
||||
> A full settings PUT would replace the player's _entire_ settings set on each
|
||||
> call; we merge instead, so a single-key PUT (e.g. `key=PlayerSessionCount`)
|
||||
@@ -18,7 +18,7 @@ Player-settings worker served on the `playersettings` subdomain.
|
||||
## KV namespace
|
||||
|
||||
```sh
|
||||
wrangler kv namespace create PLAYER_SETTINGS # then put the id in wrangler.jsonc
|
||||
wrangler kv namespace create RECFLARE_PLAYER_SETTINGS # then put the id in wrangler.jsonc
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
@@ -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' })
|
||||
})
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// Per-player settings persistence.
|
||||
"kv_namespaces": [
|
||||
{
|
||||
"binding": "PLAYER_SETTINGS",
|
||||
"binding": "RECFLARE_PLAYER_SETTINGS",
|
||||
"id": "d33a90014e904b0eac720bddcbe0b036"
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user