check / check (push) Waiting to run
Each row of the recent events on the webhook page links to the
event's own page, /hook/{id}/events/{eventID}, and expands to show its
body; only the newest starts expanded. The event's page shows its
details, its whole body and every delivery with its attempts.
One renderer, newBodyView with templates/event_body.html, shows a body
in all three places: whole up to 32 KiB, cut there in the lists with a
link to the event's page, JSON pretty-printed, a body of more than 200
lines or 32 KiB in a scrolling box, and a body that is not text left
out beside its download link. A resubmitted copy links to its
original's page.
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],
|
|
})
|
|
}
|
|
}
|