feat(api): recursively calculate directory sizes for public share folders and display on UI
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m24s

This commit is contained in:
Elijah 2026-05-23 17:27:09 -07:00
parent 755c791af5
commit 96ca68b35c
2 changed files with 25 additions and 5 deletions

View file

@ -229,9 +229,25 @@ func (h *ShareHandler) GetPublicShare(c *fiber.Ctx) error {
mimeType = "application/octet-stream"
}
getDirSize := func(p string) int64 {
var s int64
filepath.Walk(p, func(_ string, i os.FileInfo, err error) error {
if err == nil && !i.IsDir() {
s += i.Size()
}
return nil
})
return s
}
size := info.Size()
if info.IsDir() {
size = getDirSize(fullPath)
}
response := fiber.Map{
"name": info.Name(), // Use info.Name() instead of base of original path
"size": info.Size(),
"size": size,
"is_dir": info.IsDir(),
"mime_type": mimeType,
}
@ -249,9 +265,13 @@ func (h *ShareHandler) GetPublicShare(c *fiber.Ctx) error {
if eMime == "" {
eMime = "application/octet-stream"
}
entrySize := entryInfo.Size()
if entry.IsDir() {
entrySize = getDirSize(filepath.Join(fullPath, entry.Name()))
}
files = append(files, fiber.Map{
"name": entry.Name(),
"size": entryInfo.Size(),
"size": entrySize,
"is_dir": entry.IsDir(),
"mime_type": eMime,
})