feat: show disk usage of mover source with configurable warning threshold

GET /api/storage/disk-usage returns source path stats (total/used/free bytes, %).
Polls every 30s while Storage page is open.

Backend:
- migration 0009: adds mover_warning_threshold (1-99, default 80) to storage_config
- StatPath moved to internal/storage package for testability
- handleStorageDiskUsage returns {source: PathStat}

Frontend:
- DiskUsageBar component in Mergerfs Mover card: usage bar with color
  green < threshold, amber >= threshold, red >= 95%
- Warning message when threshold reached or exceeded
- New input in config form: Umbral de aviso (%)
- storageDiskUsage() API method

Tests: StatPath unit tests (empty/nonexistent/valid paths)

Version: 0.7.3
This commit is contained in:
2026-07-07 00:30:32 -04:00
parent e5b9b233b8
commit 428056e1be
9 changed files with 169 additions and 38 deletions
+13
View File
@@ -45,6 +45,10 @@ func (s *Server) handleStorageUpdateConfig(w http.ResponseWriter, r *http.Reques
writeError(w, http.StatusBadRequest, err.Error())
return
}
if cfg.MoverWarningThreshold < 1 || cfg.MoverWarningThreshold > 99 {
writeError(w, http.StatusBadRequest, "mover_warning_threshold must be between 1 and 99")
return
}
flags, err := storage.ParseExtraRsyncFlags(cfg.MoverRsyncOptions)
if err != nil {
writeError(w, http.StatusBadRequest, err.Error())
@@ -214,6 +218,15 @@ func setSSEHeaders(w http.ResponseWriter) {
w.Header().Set("X-Accel-Buffering", "no")
}
func (s *Server) handleStorageDiskUsage(w http.ResponseWriter, r *http.Request) {
cfg, err := s.DB.GetStorageConfig()
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
writeJSON(w, http.StatusOK, map[string]any{"source": storage.StatPath(cfg.MoverSource)})
}
func sseEmit(w io.Writer, event string, data any) {
body, _ := json.Marshal(data)
fmt.Fprintf(w, "event: %s\ndata: %s\n\n", event, string(body))