mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
inventions...almost working
This commit is contained in:
@@ -107,4 +107,10 @@ const app = new Hono<App>()
|
||||
// the path.
|
||||
.get('/room/:dataBlob{.+}', (c) => serveAsset(c, `room/${c.req.param('dataBlob')}`))
|
||||
|
||||
// Invention data by name. The client fetches this for an invention's
|
||||
// `CurrentVersion.BlobName` to spawn it. Streamed from R2 under `invention/`.
|
||||
// Like room blobs the name is date-foldered, and it carries the `.inv` extension
|
||||
// the upload stored it under, so the rest of the path is matched as-is.
|
||||
.get('/invention/:dataBlob{.+}', (c) => serveAsset(c, `invention/${c.req.param('dataBlob')}`))
|
||||
|
||||
export default app
|
||||
|
||||
@@ -64,4 +64,19 @@ describe('cdn endpoints', () => {
|
||||
const res = await exports.default.fetch(`${ORIGIN}/room/missing.room`)
|
||||
expect(res.status).toBe(404)
|
||||
})
|
||||
|
||||
test('GET /invention/:dataBlob streams the invention blob from R2', async () => {
|
||||
// Date-foldered, `.inv`-suffixed — the name the storage worker generates and the
|
||||
// api worker hands back as the invention's BlobName.
|
||||
const name = '2026-07-12/6f1c0c3e-1b6a-4a52-9f52-0f4a1a6d2f77.inv'
|
||||
await env.CDN_ASSETS.put(`invention/${name}`, new Uint8Array([1, 2, 3]))
|
||||
const res = await exports.default.fetch(`${ORIGIN}/invention/${name}`)
|
||||
expect(res.status).toBe(200)
|
||||
expect(new Uint8Array(await res.arrayBuffer())).toEqual(new Uint8Array([1, 2, 3]))
|
||||
})
|
||||
|
||||
test('GET /invention/:dataBlob 404s when the blob is absent', async () => {
|
||||
const res = await exports.default.fetch(`${ORIGIN}/invention/missing.inv`)
|
||||
expect(res.status).toBe(404)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user