Files

64 lines
2.2 KiB
TypeScript

import { NextResponse } from "next/server"
import { listBoardValueStreams, loadReleaseLines, type ReleaseLine } from "@/app/lib/fleet/boardSource"
export const dynamic = "force-dynamic"
/**
* GET /api/fleet/release-feed — Release-Notes-Feed (Karte tower-release-notes-feed).
*
* Chronologische Lieferliste (Release-Notes aller Wertstreams), optional
* gefiltert nach Agent (?agent=ciso) und begrenzt (?limit=50, max 500).
* Quelle: Board-PVC read-only. Nie 5xx — leere Liste + degraded im Body.
*/
export async function GET(req: Request) {
try {
const url = new URL(req.url)
const agent = (url.searchParams.get("agent") || "").trim()
const vsFilter = (url.searchParams.get("vs") || "").trim()
const limitRaw = Number(url.searchParams.get("limit") || "80")
const limit = Math.min(Math.max(Number.isFinite(limitRaw) ? limitRaw : 80, 1), 500)
let streams = listBoardValueStreams()
if (vsFilter) streams = streams.filter((s) => s === vsFilter)
let lines: ReleaseLine[] = []
for (const vs of streams) lines = lines.concat(loadReleaseLines(vs))
lines.sort((a, b) => (b.epoch ?? 0) - (a.epoch ?? 0))
const all = lines
const filtered = agent ? lines.filter((l) => l.agent === agent) : lines
const agents = [...new Set(all.map((l) => l.agent).filter(Boolean))].sort()
return NextResponse.json(
{
generated_at: new Date().toISOString(),
refresh_seconds: 30,
degraded: false,
degraded_reason: "",
total: all.length,
matching: filtered.length,
shown: Math.min(filtered.length, limit),
filter: { agent, vs: vsFilter, limit },
agents,
entries: filtered.slice(0, limit),
},
{ headers: { "Cache-Control": "no-store" } }
)
} catch (e) {
return NextResponse.json(
{
generated_at: new Date().toISOString(),
refresh_seconds: 30,
degraded: true,
degraded_reason: e instanceof Error ? e.message : String(e),
total: 0,
matching: 0,
shown: 0,
filter: { agent: "", vs: "", limit: 80 },
agents: [],
entries: [],
},
{ status: 200, headers: { "Cache-Control": "no-store" } }
)
}
}