Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/http/schemas/transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Comment thread
itslenny marked this conversation as resolved.
Comment thread
itslenny marked this conversation as resolved.
quality: { type: 'integer', minimum: 20, maximum: 100 },
} as const
2 changes: 1 addition & 1 deletion src/storage/renderer/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface TransformOptions {
width?: number
height?: number
resize?: 'cover' | 'contain' | 'fill'
format?: 'origin' | 'avif'
format?: 'origin' | 'avif' | 'webp'
quality?: number
}

Expand Down
23 changes: 23 additions & 0 deletions src/test/render-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down