import { TRPCError } from "@trpc/server"; import { put } from "@vercel/blob"; import { z } from "zod"; import { createTRPCRouter, protectedProcedure } from "../trpc"; const SVG_MAX_SIZE_BYTES = 100 * 1024; // 100KB export function isSvgFile(filename: string): boolean { return filename.toLowerCase().endsWith(".svg"); } export async function sanitizeSvg(svgContent: string): Promise { // Lazy import because root.ts merges edge + lambda routers, // so this module is evaluated in both runtimes — jsdom can't load on edge const { default: DOMPurify } = await import("isomorphic-dompurify"); return DOMPurify.sanitize(svgContent, { USE_PROFILES: { svg: true, svgFilters: true }, // DOMPurify's SVG profile strips all on* event handlers by default. // We explicitly forbid foreignObject (can embed arbitrary HTML), // and script (direct code execution). // FORBID_CONTENTS ensures text inside forbidden tags is also removed // (e.g. alert(...) text from