feat: multi-source disk entries with chips display

diskUsage now carries Sources []string instead of a single Source.
collectDiskUsage accumulates all sources (samba, nfs, manual) per path.
NFS no longer adds a redundant label to used_by.

Dashboard and Settings render one chip per source. When a path
is shared via SMB and NFS, both chips appear.

API breaking: disks[].source replaced by disks[].sources[].
Version: 0.2.1 -> 0.3.0
This commit is contained in:
2026-07-06 00:40:41 -04:00
parent a24145e07a
commit 508890a232
5 changed files with 79 additions and 31 deletions
+38 -20
View File
@@ -14,14 +14,14 @@ import (
type diskUsage struct {
Path string `json:"path"`
TotalBytes uint64 `json:"total_bytes"`
FreeBytes uint64 `json:"free_bytes"`
UsedBytes uint64 `json:"used_bytes"`
TotalBytes uint64 `json:"total_bytes"`
FreeBytes uint64 `json:"free_bytes"`
UsedBytes uint64 `json:"used_bytes"`
UsedPercent float64 `json:"used_percent"`
Source string `json:"source"`
UsedBy []string `json:"used_by,omitempty"`
Available bool `json:"available"`
Error string `json:"error,omitempty"`
Sources []string `json:"sources"`
UsedBy []string `json:"used_by,omitempty"`
Available bool `json:"available"`
Error string `json:"error,omitempty"`
}
type serviceStatus struct {
@@ -45,6 +45,15 @@ func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) {
})
}
func addSource(e *diskUsage, src string) {
for _, s := range e.Sources {
if s == src {
return
}
}
e.Sources = append(e.Sources, src)
}
func (s *Server) collectDiskUsage() []diskUsage {
entries := make(map[string]*diskUsage)
@@ -52,11 +61,13 @@ func (s *Server) collectDiskUsage() []diskUsage {
if err == nil {
for _, share := range shares {
key := share.Path
if e, ok := entries[key]; ok {
e.UsedBy = append(e.UsedBy, share.Name)
} else {
entries[key] = &diskUsage{Path: key, Source: "samba", UsedBy: []string{share.Name}, Available: true}
e, ok := entries[key]
if !ok {
e = &diskUsage{Path: key, Sources: []string{}, Available: true}
entries[key] = e
}
addSource(e, "samba")
e.UsedBy = append(e.UsedBy, share.Name)
}
}
@@ -64,12 +75,12 @@ func (s *Server) collectDiskUsage() []diskUsage {
if err == nil {
for _, exp := range exports {
key := exp.Path
label := "nfs:" + exp.Path
if e, ok := entries[key]; ok {
e.UsedBy = append(e.UsedBy, label)
} else {
entries[key] = &diskUsage{Path: key, Source: "nfs", UsedBy: []string{label}, Available: true}
e, ok := entries[key]
if !ok {
e = &diskUsage{Path: key, Sources: []string{}, Available: true}
entries[key] = e
}
addSource(e, "nfs")
}
}
@@ -77,21 +88,28 @@ func (s *Server) collectDiskUsage() []diskUsage {
if err == nil {
for _, m := range watched {
key := m.Path
if _, ok := entries[key]; !ok {
entries[key] = &diskUsage{Path: key, Source: "manual", Available: true}
e, ok := entries[key]
if !ok {
e = &diskUsage{Path: key, Sources: []string{}, Available: true}
entries[key] = e
}
addSource(e, "manual")
}
}
var result []diskUsage
for _, e := range entries {
sort.Strings(e.Sources)
fillDiskUsage(e)
result = append(result, *e)
}
sort.Slice(result, func(i, j int) bool {
if result[i].Source != result[j].Source {
return result[i].Source < result[j].Source
if len(result[i].Sources) == 0 || len(result[j].Sources) == 0 {
return len(result[i].Sources) > 0
}
if result[i].Sources[0] != result[j].Sources[0] {
return result[i].Sources[0] < result[j].Sources[0]
}
return result[i].Path < result[j].Path
})