check / check (push) Waiting to run
An expanded event in the event log and the event's own page now show the entrypoint the event arrived at (its description, "Entrypoint" when it has none, or "deleted entrypoint"; never its URL), or for a resubmitted copy the one the request it copies arrived at, and the request headers as one block of text, one line per value, sorted by name, whitespace kept. The event log leaves out headers that hold more than the body's 32 KiB limit, stored or as text, and links to the event's page, which shows them all. Both pages draw them through one shared template, event_request.html, and read the webhook's entrypoints once per page. Model: opus-5-5
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"math"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi"
|
|
"sneak.berlin/go/webhooker/internal/database"
|
|
)
|
|
|
|
// HandleEventDetail shows one event on its own page: its details,
|
|
// its whole body and every delivery of it. The page reads the
|
|
// event's body whole, which the receiver caps at 1 MB.
|
|
func (h *Handlers) HandleEventDetail() http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
webhook, ok := h.ownedWebhook(w, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
if !h.dbMgr.DBExists(webhook.ID) {
|
|
h.renderError(w, r, http.StatusNotFound)
|
|
|
|
return
|
|
}
|
|
|
|
webhookDB, err := h.dbMgr.GetDB(webhook.ID)
|
|
if err != nil {
|
|
h.serverError(w, r, "failed to get webhook database", err)
|
|
|
|
return
|
|
}
|
|
|
|
var rows []eventLogRow
|
|
|
|
err = webhookDB.Model(&database.Event{}).
|
|
Select(eventColumns).
|
|
Where(
|
|
"id = ? AND webhook_id = ?",
|
|
chi.URLParam(r, "eventID"), webhook.ID,
|
|
).
|
|
Limit(1).
|
|
Find(&rows).Error
|
|
if err != nil {
|
|
h.serverError(w, r, "failed to load event", err)
|
|
|
|
return
|
|
}
|
|
|
|
if len(rows) == 0 {
|
|
h.renderError(w, r, http.StatusNotFound)
|
|
|
|
return
|
|
}
|
|
|
|
targets, err := h.loadTargetMap(webhook.ID)
|
|
if err != nil {
|
|
h.serverError(w, r, "failed to load targets", err)
|
|
|
|
return
|
|
}
|
|
|
|
// The page shows every request header.
|
|
views, ok := h.eventLogViews(
|
|
w, r, webhookDB, webhook.ID, rows, targets, math.MaxInt,
|
|
)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
h.renderTemplate(w, r, "event_detail.html", map[string]any{
|
|
tmplKeyWebhook: &webhook,
|
|
"Event": views[0],
|
|
})
|
|
}
|
|
}
|