Files
archie/internal/webui/api_capture.go
T
sam d6b2589448 refactor(archied): move webhook capture intake to the process that owns work intake
The dashboard's POST /webhooks/capture/{source} handler becomes
internal/infrastructure/captureintake.Receiver, mounted by the daemon on
the same bypass mux through webui.Server.CaptureIntake; the dashboard
keeps only the GET /api/captures read and the mapping preview's scan
window. The UI process now mounts no intake route at all instead of one
that answers 503 (archie-core-8cda.5.4).
2026-09-10 00:35:14 +10:00

42 lines
1.6 KiB
Go

package webui
import (
"net/http"
"strconv"
)
// defaultCapturesListLimit is used when the limit query param is absent,
// non-numeric, or non-positive. A raw strconv.Atoi zero value (its error
// case) must never reach ListCaptures directly -- SQL "LIMIT 0" returns zero
// rows, which would make an unrecognised or missing limit look identical to
// "no captures exist" instead of "show the default page."
const defaultCapturesListLimit = 100
// handleCaptures lists recent captured events, newest first, for the
// dashboard's event inspector (t2db.2). Token-gated like every other
// /api/* route -- captured payloads are visible only to an authenticated
// operator, per docs/prds/webhook-intake-security.md point 5.
//
// This is the read half of event capture. The write belongs to the process
// that owns work intake (internal/infrastructure/captureintake), which the
// host mounts on the bypass mux via CaptureIntake -- the dashboard displays
// captures and mounts the route; it no longer stores them (archie-core-8cda.5.4).
func (s *Server) handleCaptures(w http.ResponseWriter, r *http.Request) {
if s.Captures == nil {
writeJSON(w, map[string]any{"captures": []any{}, "enabled": false})
return
}
limit, err := strconv.Atoi(r.URL.Query().Get("limit"))
if err != nil || limit <= 0 {
limit = defaultCapturesListLimit
}
captures, err := s.Captures.ListCaptures(r.Context(), limit)
if err != nil {
s.Log.Error("list captures", "err", err)
http.Error(w, "list captures failed", http.StatusInternalServerError)
return
}
writeJSON(w, map[string]any{"captures": captures, "enabled": true})
}