diff options
Diffstat (limited to 'internal/admin/api_triggers.go')
| -rw-r--r-- | internal/admin/api_triggers.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/internal/admin/api_triggers.go b/internal/admin/api_triggers.go index 87eb82e..5b82465 100644 --- a/internal/admin/api_triggers.go +++ b/internal/admin/api_triggers.go @@ -22,7 +22,7 @@ func (s *AdminServer) handleTriggers(w http.ResponseWriter, r *http.Request) { writeJSON(w, &YAMLTree{Root: []string{}, Dirs: map[string][]string{}}) return } - writeJSON(w, map[string]any{"error": err.Error()}) + failJSON(w, err.Error()) return } if tree == nil { @@ -32,16 +32,16 @@ func (s *AdminServer) handleTriggers(w http.ResponseWriter, r *http.Request) { case http.MethodPost: var m map[string]any if err := readJSON(r, &m); err != nil { - writeJSON(w, map[string]any{"error": "invalid json"}) + failJSON(w, "invalid json") return } id, ok := m["id"].(string) if !ok || strings.TrimSpace(id) == "" { - writeJSON(w, map[string]any{"error": "missing id"}) + failJSON(w, "missing id") return } if !validEntityID(id) { - writeJSON(w, map[string]any{"error": "invalid id"}) + failJSON(w, "invalid id") return } delete(m, "id") @@ -51,13 +51,13 @@ func (s *AdminServer) handleTriggers(w http.ResponseWriter, r *http.Request) { path := filepath.Join(s.dataDir, "triggers", subdir, id+".yaml") os.MkdirAll(filepath.Dir(path), 0755) if _, err := os.Stat(path); err == nil { - writeJSON(w, map[string]any{"error": "trigger already exists"}) + failJSON(w, "trigger already exists") return } newContent, err := writeMapAsYAML(path, m) if err != nil { - writeJSON(w, map[string]any{"error": "write error: " + err.Error()}) + failJSON(w, "write error: "+err.Error()) return } s.undoStack.Push(ChangeDesc{ @@ -87,17 +87,17 @@ func (s *AdminServer) handleTriggerByID(w http.ResponseWriter, r *http.Request) case http.MethodGet: path, _, err := findTriggerFile(s.dataDir, id) if err != nil { - writeJSON(w, map[string]any{"error": "not found: " + id}) + failJSON(w, "not found: "+id) return } data, err := os.ReadFile(path) if err != nil { - writeJSON(w, map[string]any{"error": "not found: " + id}) + failJSON(w, "not found: "+id) return } raw, err := yamlToMap(data) if err != nil { - writeJSON(w, map[string]any{"error": "parse error: " + err.Error()}) + failJSON(w, "parse error: "+err.Error()) return } raw["id"] = id @@ -109,7 +109,7 @@ func (s *AdminServer) handleTriggerByID(w http.ResponseWriter, r *http.Request) case http.MethodPut: var body map[string]any if err := readJSON(r, &body); err != nil { - writeJSON(w, map[string]any{"error": "invalid JSON: " + err.Error()}) + failJSON(w, "invalid JSON: "+err.Error()) return } delete(body, "id") @@ -134,12 +134,12 @@ func (s *AdminServer) handleTriggerByID(w http.ResponseWriter, r *http.Request) triggerData, err := triggerMapToYAML(body) if err != nil { - writeJSON(w, map[string]any{"error": "serialize error: " + err.Error()}) + failJSON(w, "serialize error: "+err.Error()) return } if err := os.WriteFile(newPath, triggerData, 0644); err != nil { - writeJSON(w, map[string]any{"error": "write error: " + err.Error()}) + failJSON(w, "write error: "+err.Error()) return } @@ -159,16 +159,16 @@ func (s *AdminServer) handleTriggerByID(w http.ResponseWriter, r *http.Request) case http.MethodDelete: path, _, err := findTriggerFile(s.dataDir, id) if err != nil { - writeJSON(w, map[string]any{"error": "not found: " + id}) + failJSON(w, "not found: "+id) return } oldContent, err := snapshotFile(path) if err != nil { - writeJSON(w, map[string]any{"error": "not found: " + id}) + failJSON(w, "not found: "+id) return } if err := os.Remove(path); err != nil { - writeJSON(w, map[string]any{"error": "delete error: " + err.Error()}) + failJSON(w, "delete error: "+err.Error()) return } s.undoStack.Push(ChangeDesc{ |
