Implement move menu tree, hover tooltips, and custom icons
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m20s

This commit is contained in:
Elijah 2026-05-23 08:13:19 -07:00
parent 3802d978ed
commit e1f009f273
4 changed files with 229 additions and 65 deletions

View file

@ -37,6 +37,12 @@ type FileInfo struct {
Checksum string `json:"checksum,omitempty"`
}
type FolderNode struct {
Name string `json:"name"`
Path string `json:"path"`
Children []*FolderNode `json:"children"`
}
// ListDirectory returns the contents of a directory.
// GET /api/files/*
func (h *FSHandler) ListDirectory(c *fiber.Ctx) error {
@ -127,6 +133,69 @@ func (h *FSHandler) ListDirectory(c *fiber.Ctx) error {
})
}
// GetFolderTree returns a hierarchical tree of all folders.
// GET /api/files/folders-tree
func (h *FSHandler) GetFolderTree(c *fiber.Ctx) error {
rootPath := h.Config.StorageDir
root := &FolderNode{
Name: "Home",
Path: ".",
Children: make([]*FolderNode, 0),
}
nodeMap := make(map[string]*FolderNode)
nodeMap["."] = root
filepath.WalkDir(rootPath, func(path string, d os.DirEntry, err error) error {
if err != nil {
return nil
}
if !d.IsDir() {
return nil
}
relPath, err := filepath.Rel(rootPath, path)
if err != nil || relPath == "." || relPath == "" {
return nil
}
base := filepath.Base(relPath)
if strings.HasPrefix(base, ".") {
return filepath.SkipDir
}
cleanPath := filepath.ToSlash(relPath)
parentPath := filepath.ToSlash(filepath.Dir(relPath))
node := &FolderNode{
Name: d.Name(),
Path: cleanPath,
Children: make([]*FolderNode, 0),
}
nodeMap[cleanPath] = node
if parentNode, exists := nodeMap[parentPath]; exists {
parentNode.Children = append(parentNode.Children, node)
}
return nil
})
var sortNode func(node *FolderNode)
sortNode = func(node *FolderNode) {
sort.Slice(node.Children, func(i, j int) bool {
return strings.ToLower(node.Children[i].Name) < strings.ToLower(node.Children[j].Name)
})
for _, child := range node.Children {
sortNode(child)
}
}
sortNode(root)
return c.JSON(root)
}
func (h *FSHandler) getFileInfo(c *fiber.Ctx, absPath string) error {
info, err := os.Stat(absPath)
if err != nil {