package webui import ( "encoding/json" "fmt" "html" "net/http" "os" "strings" "time" "bee/audit/internal/platform" ) func (h *handler) handleTaskPage(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") task, ok := globalQueue.findByID(id) if !ok { http.NotFound(w, r) return } snapshot := *task body := renderTaskDetailPage(h.opts, snapshot) w.Header().Set("Cache-Control", "no-store") w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write([]byte(body)) } func (h *handler) handleAPITaskChartsIndex(w http.ResponseWriter, r *http.Request) { task, samples, _, _, ok := h.taskSamplesForRequest(r) if !ok { http.NotFound(w, r) return } type taskChartIndexEntry struct { Title string `json:"title"` File string `json:"file"` } entries := make([]taskChartIndexEntry, 0) for _, spec := range taskChartSpecsForSamples(samples) { title, _, ok := renderTaskChartSVG(spec.Path, samples, taskTimelineForTask(task)) if !ok { continue } entries = append(entries, taskChartIndexEntry{Title: title, File: spec.File}) } w.Header().Set("Cache-Control", "no-store") w.Header().Set("Content-Type", "application/json; charset=utf-8") _ = json.NewEncoder(w).Encode(entries) } func (h *handler) handleAPITaskChartSVG(w http.ResponseWriter, r *http.Request) { task, samples, _, _, ok := h.taskSamplesForRequest(r) if !ok { http.NotFound(w, r) return } file := strings.TrimPrefix(r.URL.Path, "/api/tasks/"+task.ID+"/chart/") path, ok := taskChartPathFromFile(file) if !ok { http.NotFound(w, r) return } title, buf, hasData := renderTaskChartSVG(path, samples, taskTimelineForTask(task)) if !hasData || len(buf) == 0 || strings.TrimSpace(title) == "" { http.Error(w, "metrics history unavailable", http.StatusServiceUnavailable) return } w.Header().Set("Content-Type", "image/svg+xml") w.Header().Set("Cache-Control", "no-store") _, _ = w.Write(buf) } func renderTaskDetailPage(opts HandlerOptions, task Task) string { title := task.Name if strings.TrimSpace(title) == "" { title = task.ID } var body strings.Builder body.WriteString(`
./tasks.`)
body.WriteString(`