fix: image preview not displayed (#8207)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
Co-authored-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Alexander Onnikov 2025-03-12 06:18:29 +03:00 committed by GitHub
parent b5020fed12
commit a06c0cc5b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 11 deletions

View File

@ -131,8 +131,8 @@
blob={value.file} blob={value.file}
alt={value.name} alt={value.name}
fit={dimensions.fit} fit={dimensions.fit}
width={dimensions.width} width={Math.ceil(dimensions.width)}
height={dimensions.height} height={Math.ceil(dimensions.height)}
on:load={handleLoad} on:load={handleLoad}
on:error={handleError} on:error={handleError}
on:loadstart={handleLoadStart} on:loadstart={handleLoadStart}

View File

@ -60,10 +60,10 @@ function parseImageTransform (accept: string, transform: string): ImageTransform
image.dpr = parseFloat(value) image.dpr = parseFloat(value)
break break
case 'width': case 'width':
image.width = parseFloat(value) image.width = parseInt(value)
break break
case 'height': case 'height':
image.height = parseFloat(value) image.height = parseInt(value)
break break
} }
}) })
@ -88,14 +88,13 @@ export async function handleImageGet (
return return
} }
if (!blob.contentType.startsWith('image/')) {
res.status(400).send()
return
}
const dpr = image.dpr === undefined || Number.isNaN(image.dpr) ? 1 : image.dpr 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 width =
const height = image.height === undefined || Number.isNaN(image.height) ? undefined : image.height * dpr 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 fit = image.fit ?? 'cover'
const tempDir = mkdtempSync(join(tmpdir(), 'image-')) const tempDir = mkdtempSync(join(tmpdir(), 'image-'))