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
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m24s
This commit is contained in:
parent
755c791af5
commit
96ca68b35c
2 changed files with 25 additions and 5 deletions
|
|
@ -229,9 +229,25 @@ func (h *ShareHandler) GetPublicShare(c *fiber.Ctx) error {
|
||||||
mimeType = "application/octet-stream"
|
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{
|
response := fiber.Map{
|
||||||
"name": info.Name(), // Use info.Name() instead of base of original path
|
"name": info.Name(), // Use info.Name() instead of base of original path
|
||||||
"size": info.Size(),
|
"size": size,
|
||||||
"is_dir": info.IsDir(),
|
"is_dir": info.IsDir(),
|
||||||
"mime_type": mimeType,
|
"mime_type": mimeType,
|
||||||
}
|
}
|
||||||
|
|
@ -249,9 +265,13 @@ func (h *ShareHandler) GetPublicShare(c *fiber.Ctx) error {
|
||||||
if eMime == "" {
|
if eMime == "" {
|
||||||
eMime = "application/octet-stream"
|
eMime = "application/octet-stream"
|
||||||
}
|
}
|
||||||
|
entrySize := entryInfo.Size()
|
||||||
|
if entry.IsDir() {
|
||||||
|
entrySize = getDirSize(filepath.Join(fullPath, entry.Name()))
|
||||||
|
}
|
||||||
files = append(files, fiber.Map{
|
files = append(files, fiber.Map{
|
||||||
"name": entry.Name(),
|
"name": entry.Name(),
|
||||||
"size": entryInfo.Size(),
|
"size": entrySize,
|
||||||
"is_dir": entry.IsDir(),
|
"is_dir": entry.IsDir(),
|
||||||
"mime_type": eMime,
|
"mime_type": eMime,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
|
||||||
className="flex items-center gap-2 px-5 py-2.5 rounded-xl font-medium transition-all hover:bg-white/10 bg-white/5 border border-white/10 text-white shadow-lg"
|
className="flex items-center gap-2 px-5 py-2.5 rounded-xl font-medium transition-all hover:bg-white/10 bg-white/5 border border-white/10 text-white shadow-lg"
|
||||||
>
|
>
|
||||||
<Download className="w-4 h-4" />
|
<Download className="w-4 h-4" />
|
||||||
Download ZIP
|
Download ZIP ({formatSize(fileInfo?.size || 0)})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -287,7 +287,7 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
|
||||||
style={{ background: 'linear-gradient(135deg, #6366f1, #8b5cf6)' }}
|
style={{ background: 'linear-gradient(135deg, #6366f1, #8b5cf6)' }}
|
||||||
>
|
>
|
||||||
<Download className="w-5 h-5" />
|
<Download className="w-5 h-5" />
|
||||||
Download File
|
Download File ({formatSize(fileInfo?.size || 0)})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -326,7 +326,7 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td className="py-4 text-white/50 text-sm">
|
<td className="py-4 text-white/50 text-sm">
|
||||||
{f.is_dir ? '--' : formatSize(f.size)}
|
{formatSize(f.size)}
|
||||||
</td>
|
</td>
|
||||||
<td className="py-4 pr-4 text-right">
|
<td className="py-4 pr-4 text-right">
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
Reference in a new issue