feat(api): add target file size compression to image-to-pdf

This commit is contained in:
SnapOtter
2026-04-27 22:06:44 +08:00
parent e36b74538d
commit 444b5d80ab
2 changed files with 141 additions and 12 deletions
+28
View File
@@ -377,4 +377,32 @@ describe("image-to-pdf", () => {
const json = JSON.parse(res.body);
expect(json.pages).toBe(1);
});
// ── Target file size ──────────────────────────────────────────────
it("respects target file size and returns compression info", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ targetSize: { value: 5, unit: "MB" } }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-pdf",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.compression).toBeDefined();
expect(json.compression.targetRequested).toBe(5 * 1024 * 1024);
expect(json.compression.targetMet).toBe(true);
expect(json.compression.jpegQuality).toBeGreaterThanOrEqual(10);
expect(json.compression.jpegQuality).toBeLessThanOrEqual(95);
expect(json.processedSize).toBeLessThanOrEqual(5 * 1024 * 1024);
});
});