16 lines · 756 BRaw
| 1 | import type { Route } from "./+types/repo-last-commits"; |
| 2 | import { refsErrorCode, splatSegments, type LastChanges } from "@refs/backend/contract"; |
| 3 | import { refs, fullName, nowSeconds } from "../lib/session"; |
| 4 | |
| 5 | export 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 | } |