
























@@ -14,8 +14,8 @@ describe("tool image sanitizing", () => {
1414};
15151616const createWidePng = async () => {
17-const width = 2600;
18-const height = 400;
17+const width = 420;
18+const height = 120;
1919const raw = Buffer.alloc(width * height * 3, 0x7f);
2020return sharp(raw, {
2121raw: { width, height, channels: 3 },
@@ -25,9 +25,9 @@ describe("tool image sanitizing", () => {
2525};
26262727it("shrinks oversized images to the configured byte limit", async () => {
28-const maxBytes = 128 * 1024;
29-const width = 900;
30-const height = 900;
28+const maxBytes = 16 * 1024;
29+const width = 300;
30+const height = 300;
3131const raw = Buffer.alloc(width * height * 3, 0xff);
3232const bigPng = await sharp(raw, {
3333raw: { width, height, channels: 3 },
@@ -57,12 +57,14 @@ describe("tool image sanitizing", () => {
5757const images = [
5858{ type: "image" as const, data: png.toString("base64"), mimeType: "image/png" },
5959];
60-const { images: out, dropped } = await sanitizeImageBlocks(images, "test");
60+const { images: out, dropped } = await sanitizeImageBlocks(images, "test", {
61+maxDimensionPx: 120,
62+});
6163expect(dropped).toBe(0);
6264expect(out.length).toBe(1);
6365const meta = await sharp(Buffer.from(out[0].data, "base64")).metadata();
64-expect(meta.width).toBeLessThanOrEqual(1200);
65-expect(meta.height).toBeLessThanOrEqual(1200);
66+expect(meta.width).toBeLessThanOrEqual(120);
67+expect(meta.height).toBeLessThanOrEqual(120);
6668}, 20_000);
67696870it("shrinks images that exceed max dimension even if size is small", async () => {
@@ -76,11 +78,11 @@ describe("tool image sanitizing", () => {
7678},
7779];
788079-const out = await sanitizeContentBlocksImages(blocks, "test");
81+const out = await sanitizeContentBlocksImages(blocks, "test", { maxDimensionPx: 120 });
8082const image = getImageBlock(out);
8183const meta = await sharp(Buffer.from(image.data, "base64")).metadata();
82-expect(meta.width).toBeLessThanOrEqual(1200);
83-expect(meta.height).toBeLessThanOrEqual(1200);
84+expect(meta.width).toBeLessThanOrEqual(120);
85+expect(meta.height).toBeLessThanOrEqual(120);
8486expect(image.mimeType).toBe("image/jpeg");
8587}, 20_000);
8688此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。