init
This commit is contained in:
commit
fa6a4c650f
93 files changed
+6555
No files matched your search
@@ -0,0 +1,67 @@
|
||||
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,
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user