From b52db0b4349c8eebe6d80aa7da75052e57d4b723 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 8 May 2026 11:10:58 +0800 Subject: [PATCH] feat: portrait cards, photo storage, edit button for face gallery --- internal/storage/face_gallery_repo.go | 11 +++++++++++ internal/web/ui.go | 18 +++++++++++++++++- internal/web/ui/templates/face_gallery.html | 9 +++++---- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/internal/storage/face_gallery_repo.go b/internal/storage/face_gallery_repo.go index fb84d4b..4aca418 100644 --- a/internal/storage/face_gallery_repo.go +++ b/internal/storage/face_gallery_repo.go @@ -145,3 +145,14 @@ func (r *FaceGalleryRepo) DeletePerson(id int) error { _, err = db.Exec(`DELETE FROM face_persons WHERE id = ?`, id) return err } + +func (r *FaceGalleryRepo) RenamePerson(id int, name string) error { + db, err := r.open() + if err != nil { + return err + } + defer db.Close() + now := time.Now().Format(time.RFC3339) + _, err = db.Exec(`UPDATE face_persons SET name = ?, updated_at = ? WHERE id = ?`, name, now, id) + return err +} diff --git a/internal/web/ui.go b/internal/web/ui.go index a22250a..46e3c03 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -670,6 +670,7 @@ func (u *UI) Routes() (chi.Router, error) { r.Post("/face-gallery/build", u.actionFaceGalleryBuild) r.Post("/face-gallery/add", u.actionFaceGalleryAdd) r.Post("/face-gallery/delete", u.actionFaceGalleryDelete) + r.Post("/face-gallery/rename", u.actionFaceGalleryRename) r.Get("/monitor", u.pageMonitor) r.Get("/hls/*", u.proxyHLS) r.Get("/api/monitor/channels", u.apiMonitorChannels) @@ -4080,7 +4081,9 @@ func (u *UI) actionFaceGalleryImport(w http.ResponseWriter, r *http.Request) { if len(parts) < 2 { continue } personName := strings.TrimSpace(parts[len(parts)-2]) if personName != "" { - repo.FindOrCreatePerson(personName) + pid, _ := repo.FindOrCreatePerson(personName) + // Store relative path for display + repo.AddPhoto(pid, personName+"/"+filepath.Base(fp)) } } } @@ -4133,3 +4136,16 @@ func (u *UI) serveFacePhoto(w http.ResponseWriter, r *http.Request) { fullPath := filepath.Join("dataset", path) http.ServeFile(w, r, fullPath) } + +func (u *UI) actionFaceGalleryRename(w http.ResponseWriter, r *http.Request) { + id, _ := strconv.Atoi(r.FormValue("id")) + name := strings.TrimSpace(r.FormValue("name")) + if id <= 0 || name == "" { + http.Error(w, "invalid", http.StatusBadRequest) + return + } + if strings.TrimSpace(u.dbPath) != "" { + storage.NewFaceGalleryRepo(u.dbPath).RenamePerson(id, name) + } + http.Redirect(w, r, "/ui/face-gallery", http.StatusFound) +} diff --git a/internal/web/ui/templates/face_gallery.html b/internal/web/ui/templates/face_gallery.html index 29042ee..196dd6a 100644 --- a/internal/web/ui/templates/face_gallery.html +++ b/internal/web/ui/templates/face_gallery.html @@ -50,13 +50,13 @@ {{if .FaceGalleryPersons}}