diff --git a/src/http/schemas/transformations.ts b/src/http/schemas/transformations.ts index 907dd154a..7ca76a2e2 100644 --- a/src/http/schemas/transformations.ts +++ b/src/http/schemas/transformations.ts @@ -2,6 +2,6 @@ export const transformationOptionsSchema = { height: { type: 'integer', examples: [100], minimum: 0 }, width: { type: 'integer', examples: [100], minimum: 0 }, resize: { type: 'string', enum: ['cover', 'contain', 'fill'] }, - format: { type: 'string', enum: ['origin', 'avif'] }, + format: { type: 'string', enum: ['origin', 'avif', 'webp'] }, quality: { type: 'integer', minimum: 20, maximum: 100 }, } as const diff --git a/src/storage/renderer/image.ts b/src/storage/renderer/image.ts index 2a434df20..75263a66d 100644 --- a/src/storage/renderer/image.ts +++ b/src/storage/renderer/image.ts @@ -15,7 +15,7 @@ export interface TransformOptions { width?: number height?: number resize?: 'cover' | 'contain' | 'fill' - format?: 'origin' | 'avif' + format?: 'origin' | 'avif' | 'webp' quality?: number } diff --git a/src/test/render-routes.test.ts b/src/test/render-routes.test.ts index 6d0e0ab53..a4ac83176 100644 --- a/src/test/render-routes.test.ts +++ b/src/test/render-routes.test.ts @@ -76,6 +76,29 @@ describe('image rendering routes', () => { ) }) + it('will render a public image in all supported formats', async () => { + const formats = ['origin', 'webp', 'avif'] + const testAxios = axios.create({ baseURL: imgProxyURL }) + jest.spyOn(ImageRenderer.prototype, 'getClient').mockReturnValue(testAxios) + const axiosSpy = jest.spyOn(testAxios, 'get') + + for (let format of formats) { + const response = await appInstance.inject({ + method: 'GET', + url: `/render/image/public/public-bucket-2/favicon.ico?format=${format}&width=100&height=100`, + }) + + expect(response.statusCode).toBe(200) + expect(S3Backend.prototype.privateAssetUrl).toHaveBeenCalledTimes(1) + const expectFormat = format === 'origin' ? '' : `/format:${format}` + expect(axiosSpy).toHaveBeenCalledWith( + `/public/height:100/width:100/resizing_type:fill${expectFormat}/plain/local:///${projectRoot}/data/sadcat.jpg`, + { responseType: 'stream', signal: expect.any(AbortSignal) } + ) + jest.clearAllMocks() + } + }) + it('will render a transformed image providing a signed url', async () => { const assetUrl = 'bucket2/authenticated/casestudy.png' const signURLResponse = await appInstance.inject({