This commit is contained in:
2026-03-22 22:31:29 +01:00
parent 97d4a990a8
commit 6f87742882
16 changed files with 371 additions and 107 deletions
+43 -5
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"html/template"
"net/http"
"time"
"github.com/sirupsen/logrus"
)
@@ -27,7 +28,7 @@ func (s *State) historyHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Owner required", http.StatusBadRequest)
return
}
rows, err := s.db.Query(`SELECT u.display_name, ph.timestamp, ph.rank, ph.upload, ph.current_upload, ph.current_download, ph.points, ph.seeding_count FROM profile_history ph JOIN users u ON ph.user_id = u.id WHERE u.display_name = ? ORDER BY ph.timestamp ASC`, owner)
rows, err := s.db.Query(`SELECT ph.timestamp, ph.rank, ph.upload, ph.points, ph.seeding_count FROM profile_history ph JOIN users u ON ph.user_id = u.id WHERE u.display_name = ? ORDER BY ph.timestamp ASC`, owner)
if err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
@@ -37,8 +38,7 @@ func (s *State) historyHandler(w http.ResponseWriter, r *http.Request) {
var history []ProfileData
for rows.Next() {
var p ProfileData
if err := rows.Scan(&p.Owner, &p.Timestamp, &p.Rank, &p.Upload, &p.CurrentUpload, &p.CurrentDownload, &p.Points, &p.SeedingCount); err != nil {
logrus.Errorf("Scan history failed: %v", err)
if err := rows.Scan(&p.Timestamp, &p.Rank, &p.Upload, &p.Points, &p.SeedingCount); err != nil {
continue
}
history = append(history, p)
@@ -53,9 +53,47 @@ func (s *State) historyModalHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Owner required", http.StatusBadRequest)
return
}
fmt.Fprintf(w, `<div id="chart-data-container" data-owner="%s" x-init="renderChart('%s')"></div>`, owner, owner)
}
rows, err := s.db.Query(`SELECT ph.timestamp, ph.rank, ph.upload_bytes, ph.points, ph.seeding_count
FROM profile_history ph
JOIN users u ON ph.user_id = u.id
WHERE u.display_name = ?
ORDER BY ph.timestamp ASC`, owner)
if err != nil {
http.Error(w, "DB Error", http.StatusInternalServerError)
return
}
defer rows.Close()
res := CompactHistory{Owner: owner}
for rows.Next() {
var (
ts time.Time
rank int
uploadBytes int64
points int
seeding int
)
if err := rows.Scan(&ts, &rank, &uploadBytes, &points, &seeding); err == nil {
res.Timestamp = append(res.Timestamp, ts.Unix()*1000)
res.Rank = append(res.Rank, rank)
tib := float64(uploadBytes) / (1024 * 1024 * 1024 * 1024)
res.Upload = append(res.Upload, tib)
res.Points = append(res.Points, points)
res.Seeding = append(res.Seeding, seeding)
}
}
dataJSON, _ := json.Marshal(res)
fmt.Fprintf(w, `
<div id="chart-mount"
style="height: 100%%; width: 100%%;"
x-init='renderChart(%s)'>
</div>`, string(dataJSON))
}
func (s *State) rootHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)