From 71d789e69a5541c1af0b3204a6409209fcdb3132 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 8 May 2026 10:49:24 +0800 Subject: [PATCH] fix: register persons in app.db, async rebuild face gallery --- internal/web/ui.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/web/ui.go b/internal/web/ui.go index aa3ca09..5d24888 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -3963,7 +3963,7 @@ func (u *UI) actionFaceGalleryAdd(w http.ResponseWriter, r *http.Request) { return } defer f.Close() - u.rebuildFaceGallery() + go u.rebuildFaceGallery() io.Copy(f, file) http.Redirect(w, r, "/ui/face-gallery?msg=ok", http.StatusFound) } @@ -4024,10 +4024,10 @@ func (u *UI) actionFaceGalleryDelete(w http.ResponseWriter, r *http.Request) { http.Error(w, "invalid", http.StatusBadRequest) return } - u.rebuildFaceGallery() + go u.rebuildFaceGallery() if strings.TrimSpace(u.dbPath) != "" { repo := storage.NewFaceGalleryRepo(u.dbPath) repo.DeletePerson(id) - u.rebuildFaceGallery() + go u.rebuildFaceGallery() } http.Redirect(w, r, "/ui/face-gallery", http.StatusFound) } @@ -4075,10 +4075,25 @@ func (u *UI) actionFaceGalleryImport(w http.ResponseWriter, r *http.Request) { io.Copy(f, file) f.Close() file.Close() - u.rebuildFaceGallery() count++ } } + // Register all persons in app DB and rebuild + if strings.TrimSpace(u.dbPath) != "" { + repo := storage.NewFaceGalleryRepo(u.dbPath) + for _, files := range r.MultipartForm.File { + for _, hdr := range files { + path := strings.ReplaceAll(hdr.Filename, "\\", "/") + parts := strings.Split(path, "/") + if len(parts) < 2 { continue } + personName := strings.TrimSpace(parts[len(parts)-2]) + if personName != "" { + repo.FindOrCreatePerson(personName) + } + } + } + } + go u.rebuildFaceGallery() http.Redirect(w, r, fmt.Sprintf("/ui/face-gallery?msg=已导入 %d 张照片", count), http.StatusFound) }