feat(storage): rename snapraid_content to snapraid_conf; clarify conf vs content file; add auto-detect and conf viewer

This commit is contained in:
2026-07-07 01:17:55 -04:00
parent 047f0f5c09
commit 599af5a828
11 changed files with 143 additions and 42 deletions
+31 -3
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
"time"
@@ -31,9 +32,36 @@ func (s *Server) handleStorageGetConfig(w http.ResponseWriter, r *http.Request)
writeError(w, http.StatusInternalServerError, err.Error())
return
}
if cfg.SnapraidConf == "" {
for _, path := range []string{"/etc/snapraid.conf", "/usr/local/etc/snapraid.conf"} {
if info, err := os.Stat(path); err == nil && !info.IsDir() {
cfg.SnapraidConf = path
break
}
}
}
writeJSON(w, http.StatusOK, cfg)
}
func (s *Server) handleStorageGetConfFile(w http.ResponseWriter, r *http.Request) {
cfg, err := s.DB.GetStorageConfig()
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
if cfg.SnapraidConf == "" {
writeError(w, http.StatusBadRequest, "snapraid conf path not configured")
return
}
data, err := os.ReadFile(cfg.SnapraidConf)
if err != nil {
writeError(w, http.StatusInternalServerError, fmt.Sprintf("read %s: %v", cfg.SnapraidConf, err))
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Write(data)
}
func (s *Server) handleStorageUpdateConfig(w http.ResponseWriter, r *http.Request) {
var cfg db.StorageConfig
defer r.Body.Close()
@@ -67,9 +95,9 @@ func (s *Server) handleStorageUpdateConfig(w http.ResponseWriter, r *http.Reques
return
}
}
if cfg.SnapraidContent != "" {
if err := validateAbsPath(cfg.SnapraidContent); err != nil {
writeError(w, http.StatusBadRequest, fmt.Sprintf("snapraid_content: %v", err))
if cfg.SnapraidConf != "" {
if err := validateAbsPath(cfg.SnapraidConf); err != nil {
writeError(w, http.StatusBadRequest, fmt.Sprintf("snapraid_conf: %v", err))
return
}
}
+1
View File
@@ -92,6 +92,7 @@ func NewRouter(s *Server) chi.Router {
storageRouter.Get("/disk-usage", s.handleStorageDiskUsage)
storageRouter.Get("/config", s.handleStorageGetConfig)
storageRouter.Put("/config", s.handleStorageUpdateConfig)
storageRouter.Get("/conf-file", s.handleStorageGetConfFile)
storageRouter.Route("/jobs", func(j chi.Router) {
j.Get("/", s.handleStorageListJobs)
j.Post("/", s.handleStorageStartJob)