From 382dd0994f77072da64f38caa2e848ee87f37a88 Mon Sep 17 00:00:00 2001 From: eti Date: Tue, 4 Aug 2026 14:13:31 +0200 Subject: [PATCH] avatar: resize to the sizes the web app asks for MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The worker only understood one size, `size=tiny`, which meant 32px. It now takes 26, 34, 42 or 52 — double each size on the web app's avatar scale, so avatars stay sharp on retina screens. Anything it doesn't recognise gets the original image, untouched. `tiny` still works and still means 32px. This worker ships separately from the web app, so cached urls and a deploy that hasn't caught up yet keep asking for it. Signed-off-by: eti --- avatar/src/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/avatar/src/index.js b/avatar/src/index.js index 0b6fb3f8..47135a13 100644 --- a/avatar/src/index.js +++ b/avatar/src/index.js @@ -158,8 +158,15 @@ You can't use this directly unfortunately since all requests are signed and may ); } - const size = searchParams.get("size"); - const resizeToTiny = size === "tiny"; + const allowedWidths = [26, 34, 42, 52]; + const requestedSize = searchParams.get("size"); + + let width = null; + if (requestedSize === "tiny") { + width = 32; + } else if (allowedWidths.includes(Number(requestedSize))) { + width = Number(requestedSize); + } const format = searchParams.get("format") || "webp"; const validFormats = ["webp", "jpeg", "png"]; const outputFormat = validFormats.includes(format) ? format : "webp"; @@ -245,7 +252,7 @@ You can't use this directly unfortunately since all requests are signed and may }); const bgColor = stringToColor(actor); - const size = resizeToTiny ? 32 : 128; + const size = width ?? 128; const svg = ``; const svgData = new TextEncoder().encode(svg); @@ -261,11 +268,11 @@ You can't use this directly unfortunately since all requests are signed and may // Fetch and optionally resize the avatar let avatarResponse; - const cfOptions = outputFormat !== "webp" || resizeToTiny ? { + const cfOptions = outputFormat !== "webp" || width ? { cf: { image: { format: outputFormat, - ...(resizeToTiny ? { width: 32, height: 32, fit: "cover" } : {}), + ...(width ? { width, height: width, fit: "cover" } : {}), }, }, }: {}; -- 2.51.2