aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_dashboard.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-29 22:31:11 -0400
committerhistoria <[not public]>2026-06-29 22:31:11 -0400
commit069d3c1c81d71042706372df153254487a765dfc (patch)
treed83a4a3954d2b8304f49d83e365f4c2b075b91eb /internal/admin/api_dashboard.go
parent6c5271fb085b4571a10f106391974c249cd84317 (diff)
downloadthehouseoficarus-069d3c1c81d71042706372df153254487a765dfc.tar.gz
feat: wip web admin for mapping and crud
Diffstat (limited to 'internal/admin/api_dashboard.go')
-rw-r--r--internal/admin/api_dashboard.go39
1 files changed, 39 insertions, 0 deletions
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)
+}