updates to uuids to be consistent

This commit is contained in:
Devin Zuczek
2026-07-10 00:10:03 -04:00
parent 43c3bd93be
commit 1f70adbd67
7 changed files with 26 additions and 14 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ export const imageRoutes = new Hono<App>({ 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' },
})
+6 -2
View File
@@ -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<{