check / check (push) Waiting to run
Each event now has its own page at /hook/ID/events/EVENTID, behind the login, showing its details, its whole body and every delivery; a resubmitted copy links to its original's page. The recent events on the webhook page link there and expand to show their bodies, only the newest expanded on load. One renderer and one template show a body the same way in the recent events, the event log and the event's page: whole up to 32 KiB, cut there in the two lists with links to the event's page and the download; JSON pretty-printed unless that would grow it past four times plus 1 KiB; over 200 lines in a scrolling box; a body holding NUL or control characters treated as binary and never dumped raw. Model: opus-5-5
75 lines
1.4 KiB
Go
75 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"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
|
|
}
|
|
|
|
views, ok := h.eventLogViews(
|
|
w, r, webhookDB, webhook.ID, rows, targets,
|
|
)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
h.renderTemplate(w, r, "event_detail.html", map[string]any{
|
|
tmplKeyWebhook: &webhook,
|
|
"Event": views[0],
|
|
})
|
|
}
|
|
}
|