From fee376102192dc6f24297a7b11324636ace3a07d Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 30 Jun 2026 19:27:37 -0400 Subject: feat: admin gui object CRUD is much nicer --- internal/admin/yaml_util.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'internal/admin/yaml_util.go') diff --git a/internal/admin/yaml_util.go b/internal/admin/yaml_util.go index b97a4f2..0bc2b4a 100644 --- a/internal/admin/yaml_util.go +++ b/internal/admin/yaml_util.go @@ -86,6 +86,45 @@ func listYAMLFiles(dataDir, subdir string) ([]string, error) { return ids, nil } +type YAMLTree struct { + Root []string `json:"root"` + Dirs map[string][]string `json:"dirs"` +} + +func listYAMLTree(dataDir, subdir string) (*YAMLTree, error) { + tree := &YAMLTree{Root: []string{}, Dirs: map[string][]string{}} + base := filepath.Join(dataDir, subdir) + + entries, err := os.ReadDir(base) + if err != nil { + return nil, err + } + for _, e := range entries { + if !e.IsDir() && filepath.Ext(e.Name()) == ".yaml" { + tree.Root = append(tree.Root, e.Name()[:len(e.Name())-5]) + } + } + for _, e := range entries { + if e.IsDir() { + subPath := filepath.Join(base, e.Name()) + subEntries, err := os.ReadDir(subPath) + if err != nil { + continue + } + var ids []string + for _, se := range subEntries { + if !se.IsDir() && filepath.Ext(se.Name()) == ".yaml" { + ids = append(ids, se.Name()[:len(se.Name())-5]) + } + } + if len(ids) > 0 { + tree.Dirs[e.Name()] = ids + } + } + } + return tree, nil +} + func listYAMLFilesDeep(dataDir, subdir string) ([]string, error) { var ids []string base := filepath.Join(dataDir, subdir) -- cgit v1.2.3