fix, rm early return

This commit is contained in:
Aiden Cline
2026-05-10 23:50:58 -05:00
parent 7be017016c
commit 296be393b5
2 changed files with 18 additions and 6 deletions

View File

@@ -84,7 +84,6 @@ export const layer = Layer.effect(
const base64 = input.url.slice(input.url.indexOf(";base64,") + ";base64,".length)
const bytes = Buffer.byteLength(base64, "utf8")
if (bytes <= info.maxBase64Bytes) return input
const photon = yield* loadPhoton
@@ -99,11 +98,7 @@ export const layer = Layer.effect(
try {
const originalWidth = decoded.get_width()
const originalHeight = decoded.get_height()
if (
originalWidth <= info.maxWidth &&
originalHeight <= info.maxHeight &&
bytes <= info.maxBase64Bytes
)
if (originalWidth <= info.maxWidth && originalHeight <= info.maxHeight && bytes <= info.maxBase64Bytes)
return input
if (!info.autoResize)
return yield* new SizeError({

View File

@@ -57,6 +57,23 @@ describe("Image", () => {
}),
)
it.effect("resizes images that fit the byte limit but exceed dimension limits", () =>
Effect.gen(function* () {
const photon = yield* Effect.promise(() => import("@silvia-odwyer/photon-node"))
const source = new photon.PhotonImage(new Uint8Array(Array.from({ length: 9_000 * 4 }, () => 255)), 9_000, 1)
const image = yield* Image.Service
const result = yield* image.normalize(part("image/png", Buffer.from(source.get_bytes()).toString("base64")))
const resized = photon.PhotonImage.new_from_byteslice(
Buffer.from(result.url.slice(result.url.indexOf(";base64,") + ";base64,".length), "base64"),
)
source.free()
expect(resized.get_width()).toBeLessThanOrEqual(2_000)
expect(resized.get_height()).toBeLessThanOrEqual(2_000)
resized.free()
}),
)
tiny.effect("fails with a typed size error when no resized candidate fits", () =>
Effect.gen(function* () {
const photon = yield* Effect.promise(() => import("@silvia-odwyer/photon-node"))