1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import { withErrors, ok } from "@/lib/api";
import { requireUser } from "@/lib/auth";
import { listSources } from "@/lib/store";
import { currentState, ensureFresh, isSourceStale } from "@/lib/refresh";
// GET /api/sources — all sources with state. Each item:
// { source, hasModule, configured, snapshot, stale }.
// ?fresh=1 → refresh stale sources first (parallel)
// ?force=1 → refresh every source first (parallel)
export const GET = withErrors(async (req) => {
await requireUser(req);
const params = new URL(req.url).searchParams;
const force = params.get("force") === "1";
const fresh = force || params.get("fresh") === "1";
const sources = listSources();
if (fresh) {
await Promise.all(
sources.map((s) => ensureFresh(s, { force })),
);
}
const states = listSources().map((s) => ({
...currentState(s),
stale: isSourceStale(s),
}));
return ok({ sources: states });
});
|