feat: add backend, admin console and live monitoring

Integrate tunasync management, SQLite authentication and content settings, real monitoring and per-repository pull speeds. Add Chinese-only announcements and mirror help, editable related links, admin layout updates, deployment tools and tests.
This commit is contained in:
2026-11-01 18:04:01 +08:00
parent addadd7d15
commit f8cef413d6
57 changed files with 4222 additions and 101 deletions
+46
View File
@@ -0,0 +1,46 @@
package main
import (
"encoding/json"
"net/http"
"os"
"path/filepath"
"time"
)
type jobSpeed struct {
BytesPerSecond float64 `json:"bytesPerSecond"`
Connections int `json:"connections"`
}
type speedSnapshot struct {
UpdatedAt int64 `json:"updatedAt"`
Interval float64 `json:"interval"`
Available bool `json:"available"`
Jobs map[string]jobSpeed `json:"jobs"`
Stale bool `json:"stale"`
}
func (a *App) jobSpeeds(w http.ResponseWriter, r *http.Request) {
if a.cfg.Metrics == "" {
fail(w, 503, "SPEEDS_UNAVAILABLE")
return
}
raw, err := os.ReadFile(filepath.Join(filepath.Dir(a.cfg.Metrics), "job-speeds.json"))
var snapshot speedSnapshot
if err != nil || len(raw) > 1<<20 || json.Unmarshal(raw, &snapshot) != nil {
fail(w, 503, "SPEEDS_UNAVAILABLE")
return
}
snapshot.Stale = time.Now().UnixMilli()-snapshot.UpdatedAt > 15000 || snapshot.UpdatedAt > time.Now().Add(time.Minute).UnixMilli()
filtered := map[string]jobSpeed{}
jobs, _, code := a.cachedJobs()
if code == "" && snapshot.Available && !snapshot.Stale {
for _, job := range jobs {
if speed, exists := snapshot.Jobs[job.Name]; exists && job.Status == "syncing" && speed.BytesPerSecond >= 0 && speed.Connections >= 0 {
filtered[job.Name] = speed
}
}
}
snapshot.Jobs = filtered
respond(w, 200, snapshot)
}