diff --git a/apps/img/src/img.app.ts b/apps/img/src/img.app.ts index 33395c7..7d9cc6b 100644 --- a/apps/img/src/img.app.ts +++ b/apps/img/src/img.app.ts @@ -31,7 +31,7 @@ const CACHE_CONTROL = `public, max-age=${86400 * 30}, immutable` * number of distinct variants an attacker can request, so they can't blow past * the edge cache and force the (expensive) WASM resize on every hit. */ -const ALLOWED_DIMENSIONS = new Set([128, 256, 512, 1024]) +const ALLOWED_DIMENSIONS = new Set([64, 128, 256, 512, 1024]) /** JPEG quality used when re-encoding a resized image. */ const RESIZE_JPEG_QUALITY = 90 @@ -420,10 +420,10 @@ app.get( in: 'query', required: false, description: [ - 'Output width. Only 128, 256, 512 or 1024 are honoured — any other value is', + 'Output width. Only 64, 128, 256, 512 or 1024 are honoured — any other value is', 'ignored and the source served untouched. Given alone, height follows the aspect ratio.', ].join(' '), - schema: { type: 'integer', enum: [128, 256, 512, 1024], example: 512 }, + schema: { type: 'integer', enum: [64, 128, 256, 512, 1024], example: 512 }, }, { name: 'height', @@ -431,7 +431,7 @@ app.get( required: false, description: 'Output height, same allowed set as `width`. Given alone, width follows the aspect ratio.', - schema: { type: 'integer', enum: [128, 256, 512, 1024], example: 512 }, + schema: { type: 'integer', enum: [64, 128, 256, 512, 1024], example: 512 }, }, { name: 'cropSquare', diff --git a/apps/img/src/test/integration/api.test.ts b/apps/img/src/test/integration/api.test.ts index be7953a..523771a 100644 --- a/apps/img/src/test/integration/api.test.ts +++ b/apps/img/src/test/integration/api.test.ts @@ -128,6 +128,13 @@ describe('img endpoints', () => { expect(jpegSize(new Uint8Array(await res.arrayBuffer())).width).toBe(128) }) + it('honours the 64 width some newer endpoints request', async () => { + const res = await SELF.fetch(`${ORIGIN}/3DCharades.jpg?width=64`) + expect(res.status).toBe(200) + expect(res.headers.get('content-type')).toBe('image/jpeg') + expect(jpegSize(new Uint8Array(await res.arrayBuffer())).width).toBe(64) + }) + it('serves a static asset in preference to an R2 object of the same key', async () => { const res = await SELF.fetch(`${ORIGIN}/3DCharades.jpg`) expect(res.status).toBe(200) @@ -405,7 +412,7 @@ describe('img endpoints', () => { it('ignores a ?width outside the allowed sizes and serves the original', async () => { const full = new Uint8Array(await (await SELF.fetch(`${ORIGIN}/RecCenter.jpg`)).arrayBuffer()) - // 300 isn't one of 128/256/512/1024, so it's rejected and the source served. + // 300 isn't one of 64/128/256/512/1024, so it's rejected and the source served. const res = await SELF.fetch(`${ORIGIN}/RecCenter.jpg?width=300`) expect(res.status).toBe(200) expect(new Uint8Array(await res.arrayBuffer())).toEqual(full)