68 lines
769 B
Go
68 lines
769 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
type ExplorerNode struct {
|
|
Path string
|
|
Children []ExplorerNode
|
|
}
|
|
|
|
func (s *Server) buildExplorerTree(
|
|
path string,
|
|
depth int,
|
|
) []ExplorerNode {
|
|
|
|
if depth > 4 {
|
|
return nil
|
|
}
|
|
|
|
children, err :=
|
|
s.store.ListChildren(path)
|
|
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
var out []ExplorerNode
|
|
|
|
for _, child := range children {
|
|
|
|
node := ExplorerNode{
|
|
Path: child,
|
|
}
|
|
|
|
node.Children =
|
|
s.buildExplorerTree(
|
|
child,
|
|
depth+1,
|
|
)
|
|
|
|
out = append(out, node)
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
func (s *Server) handleExplorer(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
tree :=
|
|
s.buildExplorerTree(
|
|
"/",
|
|
0,
|
|
)
|
|
|
|
s.render(
|
|
w,
|
|
"explorer.gohtml",
|
|
map[string]any{
|
|
"Title": "Explorer",
|
|
"Tree": tree,
|
|
},
|
|
)
|
|
}
|