import type { Route } from "./+types/repo-last-commits"; import { refsErrorCode, splatSegments, type LastChanges } from "@refs/backend/contract"; import { refs, fullName, nowSeconds } from "../lib/session"; export async function loader({ params, context }: Route.LoaderArgs) { const none: LastChanges = { asOf: nowSeconds(), changes: {} }; const segments = splatSegments(params["*"]); if (!segments) return Response.json(none, { status: 404 }); try { const repo = await refs(context).repo(fullName(params)); return Response.json(await repo.lastChanges(segments), { headers: { "cache-control": "private, max-age=30" } }); } catch (error) { if (refsErrorCode(error)) return Response.json(none, { status: 404 }); throw error; } }