import type { Route } from "./+types/repo-raw"; import { refsErrorCode, splatSegments } from "@refs/backend/contract"; import { refs, fullName } from "../lib/session"; export async function loader({ params, context }: Route.LoaderArgs) { const segments = splatSegments(params["*"]); if (!segments) return new Response("Not found\n", { status: 404 }); try { const repo = await refs(context).repo(fullName(params)); const file = await repo.raw(segments); return new Response(file.body, { headers: { "content-type": file.contentType, "content-security-policy": "sandbox; default-src 'none'", "x-content-type-options": "nosniff", "cache-control": file.cacheable ? "public, max-age=60" : "private, max-age=60", }, }); } catch (error) { if (refsErrorCode(error)) return new Response("Not found\n", { status: 404 }); throw error; } }