From 069d3c1c81d71042706372df153254487a765dfc Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 29 Jun 2026 22:31:11 -0400 Subject: feat: wip web admin for mapping and crud --- internal/admin/api_dashboard.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/admin/api_dashboard.go (limited to 'internal/admin/api_dashboard.go') diff --git a/internal/admin/api_dashboard.go b/internal/admin/api_dashboard.go new file mode 100644 index 0000000..f7e7a6f --- /dev/null +++ b/internal/admin/api_dashboard.go @@ -0,0 +1,39 @@ +package admin + +import ( + "net/http" + "os" + "path/filepath" +) + +func (s *AdminServer) handleDashboard(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + + countYAML := func(subdir string) int { + dir := filepath.Join(s.dataDir, subdir) + n := 0 + filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { + if err != nil || d.IsDir() { + return nil + } + if filepath.Ext(d.Name()) == ".yaml" { + n++ + } + return nil + }) + return n + } + + dashboard := map[string]any{ + "roomCount": countYAML("rooms"), + "itemCount": countYAML("items"), + "objectCount": countYAML("objects"), + "mobCount": countYAML("mobs"), + "playerCount": countYAML("players/characters"), + "accountCount": countYAML("players/accounts"), + } + writeJSON(w, dashboard) +} -- cgit v1.2.3