mirror of
https://github.com/djdevin/recflare.git
synced 2026-10-25 23:18:51 -07:00
[img] allow 64 width
This commit is contained in:
@@ -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
|
* 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.
|
* 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. */
|
/** JPEG quality used when re-encoding a resized image. */
|
||||||
const RESIZE_JPEG_QUALITY = 90
|
const RESIZE_JPEG_QUALITY = 90
|
||||||
@@ -420,10 +420,10 @@ app.get(
|
|||||||
in: 'query',
|
in: 'query',
|
||||||
required: false,
|
required: false,
|
||||||
description: [
|
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.',
|
'ignored and the source served untouched. Given alone, height follows the aspect ratio.',
|
||||||
].join(' '),
|
].join(' '),
|
||||||
schema: { type: 'integer', enum: [128, 256, 512, 1024], example: 512 },
|
schema: { type: 'integer', enum: [64, 128, 256, 512, 1024], example: 512 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'height',
|
name: 'height',
|
||||||
@@ -431,7 +431,7 @@ app.get(
|
|||||||
required: false,
|
required: false,
|
||||||
description:
|
description:
|
||||||
'Output height, same allowed set as `width`. Given alone, width follows the aspect ratio.',
|
'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',
|
name: 'cropSquare',
|
||||||
|
|||||||
@@ -128,6 +128,13 @@ describe('img endpoints', () => {
|
|||||||
expect(jpegSize(new Uint8Array(await res.arrayBuffer())).width).toBe(128)
|
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 () => {
|
it('serves a static asset in preference to an R2 object of the same key', async () => {
|
||||||
const res = await SELF.fetch(`${ORIGIN}/3DCharades.jpg`)
|
const res = await SELF.fetch(`${ORIGIN}/3DCharades.jpg`)
|
||||||
expect(res.status).toBe(200)
|
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 () => {
|
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())
|
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`)
|
const res = await SELF.fetch(`${ORIGIN}/RecCenter.jpg?width=300`)
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(new Uint8Array(await res.arrayBuffer())).toEqual(full)
|
expect(new Uint8Array(await res.arrayBuffer())).toEqual(full)
|
||||||
|
|||||||
Reference in New Issue
Block a user