From 1dad15698845d370e998f7cc5feb8aece3fab58f Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Wed, 16 Sep 2026 17:05:17 -0400 Subject: refactor: remove dead code, consolidate save/error handling, add lint gate --- internal/admin/api_files.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'internal/admin/api_files.go') diff --git a/internal/admin/api_files.go b/internal/admin/api_files.go index ea75249..d32bda4 100644 --- a/internal/admin/api_files.go +++ b/internal/admin/api_files.go @@ -57,18 +57,18 @@ func (s *AdminServer) handleFileRename(w http.ResponseWriter, r *http.Request) { NewName string `json:"new_name"` } if err := readJSON(r, &body); err != nil || body.Path == "" || body.NewName == "" { - writeJSON(w, map[string]any{"error": "missing path or new_name"}) + failJSON(w, "missing path or new_name") return } newName := strings.TrimSpace(body.NewName) if newName == "" || newName == "." || newName == ".." || strings.ContainsAny(newName, "/\\") { - writeJSON(w, map[string]any{"error": "invalid file name"}) + failJSON(w, "invalid file name") return } for _, c := range newName { if c < 32 || c == 127 { - writeJSON(w, map[string]any{"error": "file name contains invalid characters"}) + failJSON(w, "file name contains invalid characters") return } } @@ -77,28 +77,28 @@ func (s *AdminServer) handleFileRename(w http.ResponseWriter, r *http.Request) { relPath = strings.TrimPrefix(relPath, "data/") oldAbs, err := resolveDataPath(s.dataDir, relPath) if err != nil { - writeJSON(w, map[string]any{"error": err.Error()}) + failJSON(w, err.Error()) return } oldContent, err := snapshotFile(oldAbs) if err != nil { - writeJSON(w, map[string]any{"error": "file not found: " + relPath}) + failJSON(w, "file not found: "+relPath) return } newAbs := filepath.Join(filepath.Dir(oldAbs), newName) if _, err := os.Stat(newAbs); err == nil { - writeJSON(w, map[string]any{"error": "a file named " + newName + " already exists"}) + failJSON(w, "a file named "+newName+" already exists") return } if err := os.WriteFile(newAbs, oldContent, 0644); err != nil { - writeJSON(w, map[string]any{"error": "write error: " + err.Error()}) + failJSON(w, "write error: "+err.Error()) return } if err := os.Remove(oldAbs); err != nil { - writeJSON(w, map[string]any{"error": "remove error: " + err.Error()}) + failJSON(w, "remove error: "+err.Error()) return } @@ -122,7 +122,7 @@ func (s *AdminServer) handleFiles(w http.ResponseWriter, r *http.Request) { relPath = strings.TrimPrefix(relPath, "data/") fullPath, pathErr := resolveDataPath(s.dataDir, relPath) if pathErr != nil { - writeJSON(w, map[string]any{"error": pathErr.Error()}) + failJSON(w, pathErr.Error()) return } @@ -131,7 +131,7 @@ func (s *AdminServer) handleFiles(w http.ResponseWriter, r *http.Request) { if relPath == "" { entries, err := os.ReadDir(fullPath) if err != nil { - writeJSON(w, map[string]any{"error": err.Error()}) + failJSON(w, err.Error()) return } var files []map[string]any @@ -148,14 +148,14 @@ func (s *AdminServer) handleFiles(w http.ResponseWriter, r *http.Request) { fullPath := filepath.Join(s.dataDir, relPath) info, err := os.Stat(fullPath) if err != nil { - writeJSON(w, map[string]any{"error": "not found: " + relPath}) + failJSON(w, "not found: "+relPath) return } if info.IsDir() { entries, err := os.ReadDir(fullPath) if err != nil { - writeJSON(w, map[string]any{"error": err.Error()}) + failJSON(w, err.Error()) return } var files []map[string]any @@ -171,7 +171,7 @@ func (s *AdminServer) handleFiles(w http.ResponseWriter, r *http.Request) { data, err := os.ReadFile(fullPath) if err != nil { - writeJSON(w, map[string]any{"error": "read error: " + err.Error()}) + failJSON(w, "read error: "+err.Error()) return } writeJSON(w, map[string]any{ @@ -182,12 +182,12 @@ func (s *AdminServer) handleFiles(w http.ResponseWriter, r *http.Request) { case http.MethodPut, http.MethodPost: if relPath == "" { - writeJSON(w, map[string]any{"error": "missing path"}) + failJSON(w, "missing path") return } body, err := io.ReadAll(r.Body) if err != nil { - writeJSON(w, map[string]any{"error": "read body: " + err.Error()}) + failJSON(w, "read body: "+err.Error()) return } @@ -198,12 +198,12 @@ func (s *AdminServer) handleFiles(w http.ResponseWriter, r *http.Request) { dir := filepath.Dir(fullPath) if err := os.MkdirAll(dir, 0755); err != nil { - writeJSON(w, map[string]any{"error": "mkdir: " + err.Error()}) + failJSON(w, "mkdir: "+err.Error()) return } if err := os.WriteFile(fullPath, body, 0644); err != nil { - writeJSON(w, map[string]any{"error": "write error: " + err.Error()}) + failJSON(w, "write error: "+err.Error()) return } @@ -223,12 +223,12 @@ func (s *AdminServer) handleFiles(w http.ResponseWriter, r *http.Request) { case http.MethodDelete: if relPath == "" { - writeJSON(w, map[string]any{"error": "missing path"}) + failJSON(w, "missing path") return } oldContent, _ := snapshotFile(fullPath) if err := os.Remove(fullPath); err != nil { - writeJSON(w, map[string]any{"error": "delete error: " + err.Error()}) + failJSON(w, "delete error: "+err.Error()) return } s.evictDeletedRoomFile(relPath) -- cgit v1.2.3