From a06c0cc5b7a0138c6a87061c6513ec1daee2f809 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Wed, 12 Mar 2025 06:18:29 +0300 Subject: [PATCH] fix: image preview not displayed (#8207) Signed-off-by: Alexander Onnikov Signed-off-by: Andrey Sobolev Co-authored-by: Andrey Sobolev --- .../components/AttachmentImagePreview.svelte | 4 ++-- .../datalake/pod-datalake/src/handlers/image.ts | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/plugins/attachment-resources/src/components/AttachmentImagePreview.svelte b/plugins/attachment-resources/src/components/AttachmentImagePreview.svelte index 53db098025..0e3286bc60 100644 --- a/plugins/attachment-resources/src/components/AttachmentImagePreview.svelte +++ b/plugins/attachment-resources/src/components/AttachmentImagePreview.svelte @@ -131,8 +131,8 @@ blob={value.file} alt={value.name} fit={dimensions.fit} - width={dimensions.width} - height={dimensions.height} + width={Math.ceil(dimensions.width)} + height={Math.ceil(dimensions.height)} on:load={handleLoad} on:error={handleError} on:loadstart={handleLoadStart} diff --git a/services/datalake/pod-datalake/src/handlers/image.ts b/services/datalake/pod-datalake/src/handlers/image.ts index d69d7c0430..a40c17dc58 100644 --- a/services/datalake/pod-datalake/src/handlers/image.ts +++ b/services/datalake/pod-datalake/src/handlers/image.ts @@ -60,10 +60,10 @@ function parseImageTransform (accept: string, transform: string): ImageTransform image.dpr = parseFloat(value) break case 'width': - image.width = parseFloat(value) + image.width = parseInt(value) break case 'height': - image.height = parseFloat(value) + image.height = parseInt(value) break } }) @@ -88,14 +88,13 @@ export async function handleImageGet ( return } - if (!blob.contentType.startsWith('image/')) { - res.status(400).send() - return - } - const dpr = image.dpr === undefined || Number.isNaN(image.dpr) ? 1 : image.dpr - const width = image.width === undefined || Number.isNaN(image.width) ? undefined : image.width * dpr - const height = image.height === undefined || Number.isNaN(image.height) ? undefined : image.height * dpr + const width = + image.width === undefined || Number.isNaN(image.width) ? undefined : Math.min(Math.round(image.width * dpr), 2048) + const height = + image.height === undefined || Number.isNaN(image.height) + ? undefined + : Math.min(Math.round(image.height * dpr), 2048) const fit = image.fit ?? 'cover' const tempDir = mkdtempSync(join(tmpdir(), 'image-'))