mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-13 23:52:06 +00:00
fix, rm early return
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user