const FIRST_PARTY_PERSONA_PATH = /^personas\/p[4-7]\/[a-z0-9._/-]+$/i; function notFound() { return new Response("Live2D demo assets are not part of this deployment.", { status: 404, headers: { "cache-control": "no-store", "content-type": "text/plain; charset=utf-8", "x-robots-tag": "noindex", }, }); } function normalizePathParam(value) { if (Array.isArray(value)) return value.join("/"); return String(value ?? ""); } export async function onRequest(context) { const requestedPath = normalizePathParam(context.params?.path) .replace(/^\/+/, "") .replace(/\\/g, "/"); if (requestedPath.split("/").some((segment) => segment === "." || segment === "..")) { return notFound(); } if (!FIRST_PARTY_PERSONA_PATH.test(requestedPath)) { return notFound(); } const assetResponse = context.env?.ASSETS ? await context.env.ASSETS.fetch(context.request) : null; if (!assetResponse || assetResponse.status === 404) { return notFound(); } const headers = new Headers(assetResponse.headers); headers.set("cache-control", "public, max-age=300"); headers.set("x-robots-tag", "noindex"); return new Response(assetResponse.body, { status: assetResponse.status, headers, }); }