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" } : {}), }, }, }: {};