Skip to content

Build your personal knowledge base with Trilium Notes

link previews: update image size limit

Adorian Doran09f83e65c9e8
diff --git a/apps/server/src/routes/api/link_embed.spec.ts b/apps/server/src/routes/api/link_embed.spec.ts
index 2a5cf7e528..12a94b5f00 100644
--- a/apps/server/src/routes/api/link_embed.spec.ts
+++ b/apps/server/src/routes/api/link_embed.spec.ts
@@ -180,12 +180,12 @@ describe("link-embed getMetadata", () => {
expect(decoded.bitmap.height).toBe(32);
});
- it("embeds an SVG verbatim, but drops one over 200KB", async () => {
+ it("embeds an SVG verbatim, but drops one over 100KB", async () => {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect width="10" height="10"/></svg>`;
serveImage({ payload: svg, contentType: "image/svg+xml" });
expect(parseDataUri(await imageOf() ?? "")).toMatchObject({ contentType: "image/svg+xml" });
- const hugeSvg = svg.replace("<rect", `<!--${"x".repeat(200 * 1024)}--><rect`);
+ const hugeSvg = svg.replace("<rect", `<!--${"x".repeat(100 * 1024)}--><rect`);
serveImage({ payload: hugeSvg, contentType: "image/svg+xml" });
expect(await imageOf()).toBeUndefined();
});
@@ -196,7 +196,7 @@ describe("link-embed getMetadata", () => {
serveImage({ payload: Buffer.from("RIFF????WEBPVP8 not-really"), contentType: "image/webp" });
expect(await imageOf()).toMatch(/^data:image\/webp;base64,/);
- serveImage({ payload: Buffer.alloc(300 * 1024, 1), contentType: "image/webp" });
+ serveImage({ payload: Buffer.alloc(150 * 1024, 1), contentType: "image/webp" });
expect(await imageOf()).toBeUndefined();
});
diff --git a/apps/server/src/routes/api/link_embed.ts b/apps/server/src/routes/api/link_embed.ts
index 6554963129..c3237cc5d1 100644
--- a/apps/server/src/routes/api/link_embed.ts
+++ b/apps/server/src/routes/api/link_embed.ts
@@ -20,7 +20,7 @@ const MAX_IMAGE_DOWNLOAD_SIZE = 5 * 1024 * 1024; // 5MB
* Cap for an image kept byte-for-byte instead of being re-encoded — an SVG (which scales natively,
* so rasterising it would only lose quality) or a format Jimp cannot decode (WebP, AVIF).
*/
-const MAX_VERBATIM_IMAGE_SIZE = 200 * 1024; // 200KB
+const MAX_VERBATIM_IMAGE_SIZE = 100 * 1024; // 100KB
/**
* Smallest site icon accepted as a stand-in for a missing `og:image`. Above the usual 16/32/48/64
* favicon sizes, so only a genuinely large icon qualifies — in practice the mobile home-screen one