diff options
Diffstat (limited to 'internal/admin/api_dashboard.go')
| -rw-r--r-- | internal/admin/api_dashboard.go | 39 |
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) +} |
