Skip to content

Commit

Permalink
cool delete and regular metrics update
Browse files Browse the repository at this point in the history
  • Loading branch information
trinidz committed Dec 8, 2024
2 parents ac84f37 + ab32f22 commit 6e3dc60
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 213 deletions.
72 changes: 30 additions & 42 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,34 @@ func handleFrontpage(w http.ResponseWriter, _ *http.Request) {
}
}

func handleMetricsDisplay(w http.ResponseWriter, _ *http.Request) {
items, err := getSavedEntries()
if err != nil {
log.Print("[ERROR] ", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
data := struct {
Count int
KindTextNoteCreated string
KindTextNoteDeleted string
QueryEventsRequests string
NotesBlasted string
}{
Count: len(items),
KindTextNoteCreated: getPrometheusMetric(metrics.KindTextNoteCreated.Desc()),
KindTextNoteDeleted: getPrometheusMetric(metrics.KindTextNoteDeleted.Desc()),
QueryEventsRequests: getPrometheusMetric(metrics.QueryEventsRequests.Desc()),
NotesBlasted: getPrometheusMetric(metrics.NotesBlasted.Desc()),
}

tmpl := template.Must(template.ParseFiles(fmt.Sprintf("%s/index.html", s.TemplatePath)))
if err := tmpl.ExecuteTemplate(w, "metrics-display-fragment", data); err != nil {
log.Print("[ERROR] ", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

func handleCreateFeed(w http.ResponseWriter, r *http.Request, secret *string) {
tmpl := template.Must(template.ParseFiles(fmt.Sprintf("%s/created.html", s.TemplatePath)))
metrics.CreateRequests.Inc()
entry := createFeed(r, secret)

Expand Down Expand Up @@ -98,6 +124,7 @@ func handleCreateFeed(w http.ResponseWriter, r *http.Request, secret *string) {
ErrorMessage: entry.ErrorMessage,
}

tmpl := template.Must(template.ParseFiles(fmt.Sprintf("%s/created.html", s.TemplatePath)))
err := tmpl.Execute(w, data)
if err != nil {
log.Print("[ERROR] ", err)
Expand Down Expand Up @@ -216,47 +243,8 @@ func handleDeleteFeed(w http.ResponseWriter, r *http.Request) {
log.Printf("[ERROR] could not delete feed '%q'...Error: %s ", feedPubkey, err)
}

items, err := getSavedEntries()
if err != nil {
log.Printf("[ERROR] %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}

npub, _ := nip19.EncodePublicKey(s.RelayPubkey)
tmpl := template.Must(template.ParseFiles(fmt.Sprintf("%s/index.html", s.TemplatePath)))

data := struct {
RelayName string
RelayPubkey string
RelayNPubkey string
RelayDescription string
RelayURL string
Count int
Entries []GUIEntry
KindTextNoteCreated string
KindTextNoteDeleted string
QueryEventsRequests string
NotesBlasted string
}{
RelayName: s.RelayName,
RelayPubkey: s.RelayPubkey,
RelayNPubkey: npub,
RelayDescription: s.RelayDescription,
RelayURL: s.RelayURL,
Count: len(items),
Entries: items,
KindTextNoteCreated: getPrometheusMetric(metrics.KindTextNoteCreated.Desc()),
KindTextNoteDeleted: getPrometheusMetric(metrics.KindTextNoteDeleted.Desc()),
QueryEventsRequests: getPrometheusMetric(metrics.QueryEventsRequests.Desc()),
NotesBlasted: getPrometheusMetric(metrics.NotesBlasted.Desc()),
}

http.Redirect(w, r, "/", http.StatusTemporaryRedirect)

if err := tmpl.Execute(w, data); err != nil {
log.Printf("[ERROR] %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
tmpl := template.New("t")
tmpl.Execute(w, nil)
}

func handleImportOpml(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ func main() {
mux.HandleFunc("GET /progress", handleImportProgress)
mux.HandleFunc("GET /detail", handleImportDetail)
mux.HandleFunc("GET /export", handleExportOpml)
mux.HandleFunc("GET /delete", handleDeleteFeed)
mux.HandleFunc(" /delete", handleDeleteFeed)
mux.Handle("GET /metrics", promhttp.Handler())

mux.HandleFunc(" /metricsDisplay", handleMetricsDisplay)

mux.HandleFunc("GET /health", handleHealth)
mux.HandleFunc("GET /log", handleLog)

Expand Down
8 changes: 7 additions & 1 deletion web/assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
background-color: rgb(0, 48, 153);
border-radius: .75em;
padding: .125em;
}
}

tr.htmx-swapping td {
opacity: 0;
transition: opacity 1s ease-out;
}

Loading

0 comments on commit 6e3dc60

Please sign in to comment.