feat(storage): rename snapraid_content to snapraid_conf; clarify conf vs content file; add auto-detect and conf viewer
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user