MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / HandleDashboardStats

Method HandleDashboardStats

internal/auth/auth.go:562–587  ·  view source on GitHub ↗

HandleDashboardStats returns the workspace-level aggregates for the redesigned dashboard's stats strip. Accepts ?window=N (days) to vary the lookback for inbound/outbound totals + delivery success — the dashboard at-a-glance strip omits it (defaults to 7), the settings usage card passes ?window=30.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

560// data sources and graceful-degradation behavior when usage tracking
561// is disabled.
562func (ua *UserAuth) HandleDashboardStats(w http.ResponseWriter, r *http.Request) {
563 user := ua.AuthenticateRequest(r)
564 if user == nil {
565 http.Error(w, "not authenticated", http.StatusUnauthorized)
566 return
567 }
568
569 // Parse optional ?window=N. Bad values get treated as "use default"
570 // rather than 400 — the dashboard simply shouldn't break if a
571 // caller fat-fingers the query string.
572 windowDays := 0
573 if raw := r.URL.Query().Get("window"); raw != "" {
574 if n, err := strconv.Atoi(raw); err == nil {
575 windowDays = n
576 }
577 }
578
579 stats, err := ua.store.GetDashboardStats(r.Context(), user.ID, windowDays)
580 if err != nil {
581 http.Error(w, "failed to fetch dashboard stats", http.StatusInternalServerError)
582 return
583 }
584
585 w.Header().Set("Content-Type", "application/json")
586 writeJSON(w, stats)
587}
588
589// HandleDashboardAgents lists agents owned by the authenticated user.
590func (ua *UserAuth) HandleDashboardAgents(w http.ResponseWriter, r *http.Request) {

Calls 6

AuthenticateRequestMethod · 0.95
QueryMethod · 0.80
GetDashboardStatsMethod · 0.80
writeJSONFunction · 0.70
GetMethod · 0.65
ErrorMethod · 0.45