diff --git a/src/http/routes/bucket/createBucket.ts b/src/http/routes/bucket/createBucket.ts index 911e835c..3df2cf3e 100644 --- a/src/http/routes/bucket/createBucket.ts +++ b/src/http/routes/bucket/createBucket.ts @@ -9,7 +9,7 @@ const createBucketBodySchema = { name: { type: 'string', examples: ['avatars'] }, id: { type: 'string', examples: ['avatars'] }, public: { type: 'boolean', examples: [false] }, - file_size_limit: { anyOf: [{ type: 'string' }, { type: 'integer' }] }, + file_size_limit: { anyOf: [{ type: 'integer' }, { type: 'string' }] }, allowed_mime_types: { type: 'array', items: { type: 'string' } }, }, required: ['name'], diff --git a/src/http/routes/bucket/updateBucket.ts b/src/http/routes/bucket/updateBucket.ts index 5b6d32a4..ec8b3fd7 100644 --- a/src/http/routes/bucket/updateBucket.ts +++ b/src/http/routes/bucket/updateBucket.ts @@ -7,7 +7,7 @@ const updateBucketBodySchema = { type: 'object', properties: { public: { type: 'boolean', examples: [false] }, - file_size_limit: { anyOf: [{ type: 'string' }, { type: 'integer' }] }, + file_size_limit: { anyOf: [{ type: 'integer' }, { type: 'string' }] }, allowed_mime_types: { type: 'array', items: { type: 'string' } }, }, } as const diff --git a/src/http/routes/object/getSignedURL.ts b/src/http/routes/object/getSignedURL.ts index 63123f22..8185679d 100644 --- a/src/http/routes/object/getSignedURL.ts +++ b/src/http/routes/object/getSignedURL.ts @@ -68,9 +68,10 @@ export default async function routes(fastify: FastifyInstance) { const transformationOptions = imageTransformationEnabled ? { - transformations: ImageRenderer.applyTransformation(request.body.transform || {}).join( - ',' - ), + transformations: ImageRenderer.applyTransformation( + request.body.transform || {}, + true + ).join(','), format: request.body.transform?.format || '', } : undefined diff --git a/src/storage/renderer/image.ts b/src/storage/renderer/image.ts index 9d1ccebc..3566649c 100644 --- a/src/storage/renderer/image.ts +++ b/src/storage/renderer/image.ts @@ -83,6 +83,56 @@ export class ImageRenderer extends Renderer { this.client = client } + /** + * Applies whitelisted transformations with specific limits applied + * @param options + * @param keepOriginal + */ + static applyTransformation(options: TransformOptions, keepOriginal?: boolean): string[] { + const segments = [] + + if (options.height) { + segments.push(`height:${clamp(options.height, LIMITS.height.min, LIMITS.height.max)}`) + } + + if (options.width) { + segments.push(`width:${clamp(options.width, LIMITS.width.min, LIMITS.width.max)}`) + } + + if (options.width || options.height) { + if (keepOriginal) { + segments.push(`resize:${options.resize}`) + } else { + segments.push(`resizing_type:${this.formatResizeType(options.resize)}`) + } + } + + if (options.quality) { + segments.push(`quality:${options.quality}`) + } + + if (options.format && options.format !== 'origin') { + segments.push(`format:${options.format}`) + } + + return segments + } + + protected static formatResizeType(resize: TransformOptions['resize']) { + const defaultResize = 'fill' + + switch (resize) { + case 'cover': + return defaultResize + case 'contain': + return 'fit' + case 'fill': + return 'force' + default: + return defaultResize + } + } + /** * Get the base http client */ @@ -188,51 +238,6 @@ export class ImageRenderer extends Renderer { } } - /** - * Applies whitelisted transformations with specific limits applied - * @param options - */ - static applyTransformation(options: TransformOptions): string[] { - const segments = [] - - if (options.height) { - segments.push(`height:${clamp(options.height, LIMITS.height.min, LIMITS.height.max)}`) - } - - if (options.width) { - segments.push(`width:${clamp(options.width, LIMITS.width.min, LIMITS.width.max)}`) - } - - if (options.width || options.height) { - segments.push(`resizing_type:${this.formatResizeType(options.resize)}`) - } - - if (options.quality) { - segments.push(`quality:${options.quality}`) - } - - if (options.format && options.format !== 'origin') { - segments.push(`format:${options.format}`) - } - - return segments - } - - protected static formatResizeType(resize: TransformOptions['resize']) { - const defaultResize = 'fill' - - switch (resize) { - case 'cover': - return defaultResize - case 'contain': - return 'fit' - case 'fill': - return 'force' - default: - return defaultResize - } - } - protected async handleRequestError(error: AxiosError) { const stream = error.response?.data as Stream if (!stream) {