diff options
Diffstat (limited to 'internal/admin/api_rooms_bulk.go')
| -rw-r--r-- | internal/admin/api_rooms_bulk.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/internal/admin/api_rooms_bulk.go b/internal/admin/api_rooms_bulk.go index a7fcee7..d10e0e3 100644 --- a/internal/admin/api_rooms_bulk.go +++ b/internal/admin/api_rooms_bulk.go @@ -44,23 +44,23 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) { body, readErr := io.ReadAll(r.Body) r.Body.Close() if readErr != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("read body: %v", readErr)}) + failJSON(w, fmt.Sprintf("read body: %v", readErr)) return } var req bulkEditRequest if err := json.Unmarshal(body, &req); err != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("invalid json: %v", err)}) + failJSON(w, fmt.Sprintf("invalid json: %v", err)) return } if len(req.IDs) == 0 { - writeJSON(w, map[string]any{"error": "no room ids"}) + failJSON(w, "no room ids") return } if isEmptyPatch(req.Patch) { - writeJSON(w, map[string]any{"error": "no patch fields"}) + failJSON(w, "no patch fields") return } @@ -78,17 +78,17 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) { for _, id := range req.IDs { path, ok := s.world.GetRoomPath(id) if !ok { - writeJSON(w, map[string]any{"error": fmt.Sprintf("room %d not found", id)}) + failJSON(w, fmt.Sprintf("room %d not found", id)) return } oldContent, err := os.ReadFile(path) if err != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("read room %d: %v", id, err)}) + failJSON(w, fmt.Sprintf("read room %d: %v", id, err)) return } m, yamlErr := yamlToMap(oldContent) if yamlErr != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("parse room %d: %v", id, yamlErr)}) + failJSON(w, fmt.Sprintf("parse room %d: %v", id, yamlErr)) return } @@ -110,13 +110,13 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) { if patch.Dir != nil && *patch.Dir != "" { destDir := filepath.Join(s.dataDir, "rooms", *patch.Dir) if _, statErr := os.Stat(destDir); os.IsNotExist(statErr) { - writeJSON(w, map[string]any{"error": fmt.Sprintf("directory does not exist: %s", *patch.Dir)}) + failJSON(w, fmt.Sprintf("directory does not exist: %s", *patch.Dir)) return } newPath = filepath.Join(destDir, strconv.Itoa(id)+".yaml") if newPath != path { if _, statErr := os.Stat(newPath); statErr == nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("room %d already exists in target directory", id)}) + failJSON(w, fmt.Sprintf("room %d already exists in target directory", id)) return } } @@ -127,7 +127,7 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) { newContent, marshalErr := marshalMapYAML(m) if marshalErr != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("marshal room %d: %v", id, marshalErr)}) + failJSON(w, fmt.Sprintf("marshal room %d: %v", id, marshalErr)) return } writes = append(writes, roomWrite{id: id, oldPath: path, newPath: newPath, oldContent: oldContent, newContent: newContent}) @@ -138,17 +138,17 @@ func (s *AdminServer) handleBulkEdit(w http.ResponseWriter, r *http.Request) { for _, wr := range writes { if wr.newPath != wr.oldPath { if err := txn.Move(wr.oldPath, wr.newPath); err != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("move room %d: %v", wr.id, err)}) + failJSON(w, fmt.Sprintf("move room %d: %v", wr.id, err)) return } } if err := txn.Replace(wr.newPath, wr.newContent, 0644); err != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("write room %d: %v", wr.id, err)}) + failJSON(w, fmt.Sprintf("write room %d: %v", wr.id, err)) return } } if err := txn.Commit(); err != nil { - writeJSON(w, map[string]any{"error": fmt.Sprintf("commit bulk edit: %v", err)}) + failJSON(w, fmt.Sprintf("commit bulk edit: %v", err)) return } |
