From 1f70adbd67f76f45ae8468d2a716d36aec0161a7 Mon Sep 17 00:00:00 2001 From: Devin Zuczek Date: Fri, 10 Jul 2026 00:10:03 -0400 Subject: [PATCH] updates to uuids to be consistent --- apps/api/src/routes/images.ts | 2 +- apps/api/src/test/integration/api.test.ts | 8 ++++++-- apps/auth/src/refresh-db.ts | 5 ++--- apps/cdn/src/cdn.app.ts | 6 ++++-- apps/storage/src/storage.app.ts | 11 ++++++++--- apps/storage/src/test/integration/api.test.ts | 4 +++- packages/jwt/src/jwt.ts | 4 ++-- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/apps/api/src/routes/images.ts b/apps/api/src/routes/images.ts index ee761e1..fc5628f 100644 --- a/apps/api/src/routes/images.ts +++ b/apps/api/src/routes/images.ts @@ -64,7 +64,7 @@ export const imageRoutes = new Hono({ strict: false }) // The `img` worker serves it back by that key (slashes and all), which is the // returned ImageName. const datePrefix = new Date().toISOString().slice(0, 10) + '/' - const name = datePrefix + crypto.randomUUID().replace(/-/g, '') + extension + const name = datePrefix + crypto.randomUUID() + extension await c.env.IMAGES.put(name, await file.arrayBuffer(), { httpMetadata: { contentType: file.type || 'image/jpeg' }, }) diff --git a/apps/api/src/test/integration/api.test.ts b/apps/api/src/test/integration/api.test.ts index bfcbf2b..94b50b1 100644 --- a/apps/api/src/test/integration/api.test.ts +++ b/apps/api/src/test/integration/api.test.ts @@ -325,7 +325,9 @@ describe('images', () => { }) expect(res.status).toBe(200) const { ImageName } = (await res.json()) as { ImageName: string } - expect(ImageName).toMatch(/^\d{4}-\d{2}-\d{2}\/[0-9a-f]+\.png$/) + expect(ImageName).toMatch( + /^\d{4}-\d{2}-\d{2}\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.png$/ + ) // The object is in the shared bucket under that key. const stored = await env.IMAGES.get(ImageName) @@ -470,7 +472,9 @@ describe('images', () => { }) expect(res.status).toBe(200) const { ImageName } = (await res.json()) as { ImageName: string } - expect(ImageName).toMatch(/^\d{4}-\d{2}-\d{2}\/[0-9a-f]+\.jpg$/) + expect(ImageName).toMatch( + /^\d{4}-\d{2}-\d{2}\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.jpg$/ + ) // The account row now points its profileImage at the uploaded key. const row = await env.DB.prepare('SELECT data FROM accounts WHERE account_id = 42').first<{ diff --git a/apps/auth/src/refresh-db.ts b/apps/auth/src/refresh-db.ts index 2d8d127..ff6d2bf 100644 --- a/apps/auth/src/refresh-db.ts +++ b/apps/auth/src/refresh-db.ts @@ -38,11 +38,10 @@ async function hashToken(token: string): Promise { /** * Mint and persist a new refresh token for the given login, returning the raw - * token — the only moment it exists in plaintext (only its hash is stored). The - * `-1` suffix mirrors the shape the client expects. + * token — the only moment it exists in plaintext (only its hash is stored). */ export async function issueRefreshToken(db: D1Database, ctx: RefreshContext): Promise { - const token = `${crypto.randomUUID().replace(/-/g, '').toUpperCase()}-1` + const token = `${crypto.randomUUID()}` const now = Math.floor(Date.now() / 1000) await db .prepare( diff --git a/apps/cdn/src/cdn.app.ts b/apps/cdn/src/cdn.app.ts index 3d8c5d2..08db9a1 100644 --- a/apps/cdn/src/cdn.app.ts +++ b/apps/cdn/src/cdn.app.ts @@ -102,7 +102,9 @@ const app = new Hono() .get('/sigs/:sigName', (c) => serveAsset(c, `sigs/${c.req.param('sigName')}`)) // Room build data by name. The client fetches this for a SubRoom's DataBlob to - // load the room. Streamed from R2 under `room/`. - .get('/room/:dataBlob', (c) => serveAsset(c, `room/${c.req.param('dataBlob')}`)) + // load the room. Streamed from R2 under `room/`. The name may contain slashes + // (uploads are foldered by date, e.g. `2026-02-03/`), so match the rest of + // the path. + .get('/room/:dataBlob{.+}', (c) => serveAsset(c, `room/${c.req.param('dataBlob')}`)) export default app diff --git a/apps/storage/src/storage.app.ts b/apps/storage/src/storage.app.ts index 4164105..465ed48 100644 --- a/apps/storage/src/storage.app.ts +++ b/apps/storage/src/storage.app.ts @@ -14,7 +14,7 @@ import type { App } from './context' /** * The client's `UploadFileType` enum → the R2 subfolder uploads of that type are - * stored under. `Unknown` (0) is intentionally absent: like the reference + * stored under. `Unknown` (0) is intentionally absent: like the referencecdn * server's `makeUploadName`, an unrecognized type has no destination and is * rejected rather than stored. * @@ -65,7 +65,8 @@ const app = new Hono() // File upload. Auth-gated — any valid account token is allowed (no role check). // Multipart form with `FileType` (the client's UploadFileType enum) and a binary // part. Stores the file in the shared CDN R2 bucket under - // `/` and returns the generated filename the client + // `//` and returns the generated name + // (the `/` part the `cdn` worker serves back) the client // references it by. Also accepts a name-only post (no binary) that just echoes // back an explicit `name`/`filename`/`imagename`. Mirrors the reference `Upload`. .post('/upload', async (c) => { @@ -84,7 +85,11 @@ const app = new Hono() // makeUploadName == "" → no destination for an unknown/missing type. return c.json({ error: 'missing or unknown FileType' }, 400) } - const filename = crypto.randomUUID().replace(/-/g, '') + // Folder each upload under its date (e.g. `room/2026-02-03/`) so the + // bucket stays browsable. The date is part of the returned name, so the key + // the `cdn` worker reads back (`/`) still round-trips. + const datePrefix = new Date().toISOString().slice(0, 10) + const filename = `${datePrefix}/${crypto.randomUUID()}` await c.env.CDN_ASSETS.put(`${subfolder}/${filename}`, await file.arrayBuffer(), { httpMetadata: { contentType: file.type || 'application/octet-stream' }, }) diff --git a/apps/storage/src/test/integration/api.test.ts b/apps/storage/src/test/integration/api.test.ts index 67be6a8..a49f51b 100644 --- a/apps/storage/src/test/integration/api.test.ts +++ b/apps/storage/src/test/integration/api.test.ts @@ -73,7 +73,9 @@ it('POST /upload stores a RoomMetadata (FileType 6) file under roommetadata/ and }) expect(res.status).toBe(200) const { filename } = (await res.json()) as { filename: string } - expect(filename).toMatch(/^[0-9a-f]{32}$/) + expect(filename).toMatch( + /^\d{4}-\d{2}-\d{2}\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ + ) // The bytes are persisted in the shared CDN bucket under the type subfolder. const stored = await env.CDN_ASSETS.get(`roommetadata/${filename}`) diff --git a/packages/jwt/src/jwt.ts b/packages/jwt/src/jwt.ts index 1448464..2b30eb5 100644 --- a/packages/jwt/src/jwt.ts +++ b/packages/jwt/src/jwt.ts @@ -95,11 +95,11 @@ export async function generateToken( idp: 'local', platform, platform_id: platformId, - 'rn.ver': '20210129', + 'rn.ver': '20230302', 'rn.plat': '0', role: TOKEN_ROLES, scope: TOKEN_SCOPES, - jti: crypto.randomUUID().replace(/-/g, '').toUpperCase(), + jti: crypto.randomUUID(), }, secret )