Skip to content
refs
History
16 lines · 756 BRaw
1import type { Route } from "./+types/repo-last-commits";
2import { refsErrorCode, splatSegments, type LastChanges } from "@refs/backend/contract";
3import { refs, fullName, nowSeconds } from "../lib/session";
4
5export async function loader({ params, context }: Route.LoaderArgs) {
6 const none: LastChanges = { asOf: nowSeconds(), changes: {} };
7 const segments = splatSegments(params["*"]);
8 if (!segments) return Response.json(none, { status: 404 });
9 try {
10 const repo = await refs(context).repo(fullName(params));
11 return Response.json(await repo.lastChanges(segments), { headers: { "cache-control": "private, max-age=30" } });
12 } catch (error) {
13 if (refsErrorCode(error)) return Response.json(none, { status: 404 });
14 throw error;
15 }
16}