fix: use actual filename for face_gallery resource name, add dedup

This commit is contained in:
tian 2026-05-06 13:37:55 +08:00
parent 8a9ec59134
commit daa5da3b85
2 changed files with 14 additions and 2 deletions

View File

@ -43,8 +43,9 @@ func (s *Server) handleResourcesStatus(w http.ResponseWriter, r *http.Request) {
fgPath := filepath.Join(s.agentCfg.ModelsDir, "face_gallery.db")
if st, err := os.Stat(fgPath); err == nil {
sha, _ := fileSHA256HTTP(fgPath)
name := strings.TrimSuffix(filepath.Base(fgPath), filepath.Ext(fgPath))
resources = append(resources, installedResource{
Name: "face_gallery_v1",
Name: name,
ResourceType: "face_gallery",
SHA256: sha,
SizeBytes: st.Size(),
@ -95,7 +96,18 @@ func (s *Server) handleResourcesStatus(w http.ResponseWriter, r *http.Request) {
return resources[i].Name < resources[j].Name
})
writeJSON(w, http.StatusOK, map[string]any{"resources": resources})
// dedup by resource_type + name (face_gallery.db may appear both in modelsDir and resources/)
seen := make(map[string]bool, len(resources))
deduped := make([]installedResource, 0, len(resources))
for _, r := range resources {
key := r.ResourceType + "/" + r.Name
if !seen[key] {
seen[key] = true
deduped = append(deduped, r)
}
}
writeJSON(w, http.StatusOK, map[string]any{"resources": deduped})
}
// handleResourceUpload accepts a resource file upload.

Binary file not shown.