{"release_id":"01a1998d-9802-0000-b0f7-33a23307f4ed","chunk_id":"01a1998d-9821-7a22-9a57-d38c0504314b","file":"BP9ijS9U.mjs","mappings":"wVA+BO,MAAMA,EAAM,CAClB,OAAQ,CAAE,MAAO,IAAK,QAAS,EAAA,EAC/B,MAAO,CAAE,MAAO,KAAM,QAAS,EAAA,CAIhC,EAQO,SAASC,EACfC,EACAC,EACAC,EACgB,CAChB,GAAI,CAACD,EAAM,OAAO,KAClB,MAAME,EAAQ,OAAOF,CAAI,EAAE,QAAQ,OAAQ,EAAE,EAEvCG,EAAMC,EAAI,gBAAgB,QAAQ,OAAQ,EAAE,EAClD,GAAID,EAAK,CACR,MAAME,EAAO,GAAGF,CAAG,IAAIJ,CAAM,IAAIG,CAAK,GAChCI,EAAI,IAAI,gBACVL,GAAW,OAAOK,EAAE,IAAI,QAAS,OAAO,KAAK,MAAML,EAAU,KAAK,CAAC,CAAC,EACpEA,GAAW,QAAQK,EAAE,IAAI,SAAU,OAAO,KAAK,MAAML,EAAU,MAAM,CAAC,CAAC,EACvEA,GAAW,SAASK,EAAE,IAAI,UAAW,OAAOL,EAAU,OAAO,CAAC,EAClE,MAAMM,EAAKD,EAAE,SAAA,EACb,OAAOC,EAAK,GAAGF,CAAI,IAAIE,CAAE,GAAKF,CAC/B,CAEA,OAAOG,EAAkBT,EAAQC,CAAI,CACtC,CAUO,SAASQ,EAAkBT,EAAgBC,EAAgD,CACjG,GAAI,CAACA,EAAM,OAAO,KAClB,MAAME,EAAQ,OAAOF,CAAI,EAAE,QAAQ,OAAQ,EAAE,EACvCS,EAAOL,EAAI,oBACjB,OAAKK,EACE,GAAGA,CAAI,6BAA6BV,CAAM,IAAIG,CAAK,GADxC,IAEnB","names":["IMG","publicMediaUrl","bucket","path","transform","clean","cdn","env","base","q","qs","supabasePublicUrl","supa"],"sources":["../../../../../../src/lib/cdn.ts"],"sourcesContent":["import { env } from '$env/dynamic/public';\n\n/**\n * Media delivery via Bunny CDN (Phase 1 — public buckets).\n *\n * A single Bunny pull zone sits in front of Supabase Storage's public endpoint:\n *   origin  = `${PUBLIC_SUPABASE_URL}/storage/v1/object/public/`\n *   host    = `${PUBLIC_CDN_URL}`   (e.g. https://ratemyd.b-cdn.net)\n * so `${PUBLIC_CDN_URL}/<bucket>/<path>` maps 1:1 to the origin object, and\n * Bunny Optimizer resizes on the fly from `?width=&height=&quality=`.\n *\n * The whole thing is behind PUBLIC_CDN_URL: when it is unset we return the plain\n * Supabase public URL (today's behaviour), so shipping this is a no-op until the\n * Bunny zone is configured and the env var is set.\n */\n\nexport type ImgTransform = {\n\t/** target width in px — Bunny Optimizer resizes + edge-caches the variant */\n\twidth?: number;\n\t/** target height in px */\n\theight?: number;\n\t/** 1–100 (Optimizer default ≈ 85) */\n\tquality?: number;\n};\n\n/**\n * Size presets by surface. Chrome (avatars/covers) is already sharp-webp'd on\n * upload, so its sizes are generous safety caps — the win there is the edge\n * cache. Content (arena/feed) is stored raw (up to 5 MB), so its feed sizes are\n * the real payload win: a 5 MB original becomes an ~80 KB webp thumbnail.\n */\nexport const IMG = {\n\tavatar: { width: 256, quality: 85 },\n\tcover: { width: 1400, quality: 82 },\n\tfeed: { width: 1080, quality: 80 },\n\tgrid: { width: 520, quality: 78 },\n\tfull: { width: 1600, quality: 85 }\n} as const satisfies Record<string, ImgTransform>;\n\n/**\n * Delivery URL for a file in a PUBLIC Supabase Storage bucket. Returns null for\n * an empty path (callers fall back to their placeholder). When PUBLIC_CDN_URL is\n * set the file is served from the Bunny edge with any `transform` applied;\n * otherwise it falls back to the Supabase public URL.\n */\nexport function publicMediaUrl(\n\tbucket: string,\n\tpath: string | null | undefined,\n\ttransform?: ImgTransform\n): string | null {\n\tif (!path) return null;\n\tconst clean = String(path).replace(/^\\/+/, '');\n\n\tconst cdn = env.PUBLIC_CDN_URL?.replace(/\\/+$/, '');\n\tif (cdn) {\n\t\tconst base = `${cdn}/${bucket}/${clean}`;\n\t\tconst q = new URLSearchParams();\n\t\tif (transform?.width) q.set('width', String(Math.round(transform.width)));\n\t\tif (transform?.height) q.set('height', String(Math.round(transform.height)));\n\t\tif (transform?.quality) q.set('quality', String(transform.quality));\n\t\tconst qs = q.toString();\n\t\treturn qs ? `${base}?${qs}` : base;\n\t}\n\n\treturn supabasePublicUrl(bucket, path);\n}\n\n/**\n * The plain Supabase Storage public URL for a file, bypassing Bunny + the\n * Optimizer entirely. Used as a client-side fallback when the CDN/Optimizer URL\n * fails to load — a just-uploaded object can come back broken through the\n * Optimizer (cold edge / negative cache / decode of the raw original) while the\n * direct origin object is already retrievable. Returns null for an empty path or\n * when PUBLIC_SUPABASE_URL is unset (callers fall back to their placeholder).\n */\nexport function supabasePublicUrl(bucket: string, path: string | null | undefined): string | null {\n\tif (!path) return null;\n\tconst clean = String(path).replace(/^\\/+/, '');\n\tconst supa = env.PUBLIC_SUPABASE_URL;\n\tif (!supa) return null;\n\treturn `${supa}/storage/v1/object/public/${bucket}/${clean}`;\n}\n"],"version":3}