fix: image resizer wasm loading, reenable image resizing (#26805)

This commit is contained in:
Aiden Cline
2026-05-13 23:06:07 -05:00
committed by GitHub
parent c50d2b3656
commit 981e00971a
8 changed files with 419 additions and 66 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB

View File

@@ -2,6 +2,7 @@ import { describe, expect } from "bun:test"
import { Cause, Effect, Exit, Layer } from "effect"
import { Image } from "@/image/image"
import { MessageID, PartID, SessionID } from "@/session/schema"
import path from "node:path"
import { TestConfig } from "../fixture/config"
import { testEffect } from "../lib/effect"
@@ -57,6 +58,46 @@ 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()
}),
)
it.effect("resizes the 5MB base64 picture fixture", () =>
Effect.gen(function* () {
const photon = yield* Effect.promise(() => import("@silvia-odwyer/photon-node"))
const data = Buffer.from(
yield* Effect.promise(() =>
Bun.file(path.join(import.meta.dir, "fixtures", "picture-5mb-base64.png")).arrayBuffer(),
),
)
const input = part("image/png", data.toString("base64"))
const image = yield* Image.Service
const result = yield* image.normalize(input)
const base64 = result.url.slice(result.url.indexOf(";base64,") + ";base64,".length)
const resized = photon.PhotonImage.new_from_byteslice(Buffer.from(base64, "base64"))
expect(input.url.slice(input.url.indexOf(";base64,") + ";base64,".length).length).toBe(5 * 1024 * 1024)
expect(result.url).not.toBe(input.url)
expect(base64.length).toBeLessThan(5 * 1024 * 1024)
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"))