aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/server.go')
-rw-r--r--internal/admin/server.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/admin/server.go b/internal/admin/server.go
index b1f641a..04e68a6 100644
--- a/internal/admin/server.go
+++ b/internal/admin/server.go
@@ -118,24 +118,31 @@ func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStor
apiMux.HandleFunc("/api/rooms/new-empty", s.handleCreateEmptyRoom)
apiMux.HandleFunc("/api/rooms/", s.handleRoomByID)
apiMux.HandleFunc("/api/objects/move", s.handleEntityMove("objects"))
+ apiMux.HandleFunc("/api/objects/dirs", s.handleEntityDirs("objects"))
apiMux.HandleFunc("/api/objects", s.handleObjects)
apiMux.HandleFunc("/api/objects/", s.handleObjectByID)
apiMux.HandleFunc("/api/items/move", s.handleEntityMove("items"))
+ apiMux.HandleFunc("/api/items/dirs", s.handleEntityDirs("items"))
apiMux.HandleFunc("/api/items", s.handleItems)
apiMux.HandleFunc("/api/items/", s.handleItemByID)
apiMux.HandleFunc("/api/mobs/move", s.handleEntityMove("mobs"))
+ apiMux.HandleFunc("/api/mobs/dirs", s.handleEntityDirs("mobs"))
apiMux.HandleFunc("/api/mobs", s.handleMobs)
apiMux.HandleFunc("/api/mobs/", s.handleMobByID)
apiMux.HandleFunc("/api/drops/move", s.handleEntityMove("drops"))
+ apiMux.HandleFunc("/api/drops/dirs", s.handleEntityDirs("drops"))
apiMux.HandleFunc("/api/drops", s.handleDrops)
apiMux.HandleFunc("/api/drops/", s.handleDropByID)
apiMux.HandleFunc("/api/hazards/move", s.handleEntityMove("hazards"))
+ apiMux.HandleFunc("/api/hazards/dirs", s.handleEntityDirs("hazards"))
apiMux.HandleFunc("/api/hazards", s.handleHazards)
apiMux.HandleFunc("/api/hazards/", s.handleHazardByID)
apiMux.HandleFunc("/api/techs/move", s.handleEntityMove("techs"))
+ apiMux.HandleFunc("/api/techs/dirs", s.handleEntityDirs("techs"))
apiMux.HandleFunc("/api/techs", s.handleTechs)
apiMux.HandleFunc("/api/techs/", s.handleTechByID)
apiMux.HandleFunc("/api/modules/move", s.handleEntityMove("modules"))
+ apiMux.HandleFunc("/api/modules/dirs", s.handleEntityDirs("modules"))
apiMux.HandleFunc("/api/modules", s.handleModules)
apiMux.HandleFunc("/api/modules/", s.handleModuleByID)
apiMux.HandleFunc("/api/players", s.handlePlayers)
@@ -466,6 +473,44 @@ func (s *AdminServer) doRedo(w http.ResponseWriter, r *http.Request) {
writeJSON(w, resp)
}
+func (s *AdminServer) handleEntityDirs(entityType string) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost {
+ http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
+ return
+ }
+ var body struct {
+ Action string `json:"action"`
+ Name string `json:"name"`
+ Dir string `json:"dir"`
+ }
+ if err := readJSON(r, &body); err != nil {
+ writeJSON(w, map[string]any{"error": "invalid"})
+ return
+ }
+ switch body.Action {
+ case "create":
+ if err := createEntityDir(s.dataDir, entityType, body.Name); err != nil {
+ writeJSON(w, map[string]any{"error": err.Error()})
+ return
+ }
+ writeJSON(w, map[string]any{"ok": true, "name": body.Name})
+ case "delete":
+ changes, err := deleteEntityDir(s.dataDir, entityType, body.Dir)
+ if err != nil {
+ writeJSON(w, map[string]any{"error": err.Error()})
+ return
+ }
+ for _, ch := range changes {
+ s.undoStack.Push(ch)
+ }
+ writeJSON(w, map[string]any{"ok": true, "moved": len(changes) - 1})
+ default:
+ writeJSON(w, map[string]any{"error": "unknown action"})
+ }
+ }
+}
+
func (s *AdminServer) handleEntityMove(entityType string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {