From 96e94a1519bae4269497c6f524195ded14feb76a Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 8 May 2026 11:16:55 +0800 Subject: [PATCH] feat: edit modal with photo management for face gallery --- internal/web/ui.go | 26 ++++++++++++ internal/web/ui/templates/face_gallery.html | 44 ++++++++++++++++----- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/internal/web/ui.go b/internal/web/ui.go index 46e3c03..45cf6bd 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -671,6 +671,7 @@ func (u *UI) Routes() (chi.Router, error) { r.Post("/face-gallery/add", u.actionFaceGalleryAdd) r.Post("/face-gallery/delete", u.actionFaceGalleryDelete) r.Post("/face-gallery/rename", u.actionFaceGalleryRename) + r.Post("/face-gallery/add-photo", u.actionFaceGalleryAddPhoto) r.Get("/monitor", u.pageMonitor) r.Get("/hls/*", u.proxyHLS) r.Get("/api/monitor/channels", u.apiMonitorChannels) @@ -4149,3 +4150,28 @@ func (u *UI) actionFaceGalleryRename(w http.ResponseWriter, r *http.Request) { } http.Redirect(w, r, "/ui/face-gallery", http.StatusFound) } + +func (u *UI) actionFaceGalleryAddPhoto(w http.ResponseWriter, r *http.Request) { + if err := r.ParseMultipartForm(10 << 20); err != nil { http.Error(w, "form error", http.StatusBadRequest); return } + id, _ := strconv.Atoi(r.FormValue("id")) + if id <= 0 { http.Error(w, "invalid id", http.StatusBadRequest); return } + file, hdr, err := r.FormFile("photo") + if err != nil { http.Error(w, "photo required", http.StatusBadRequest); return } + defer file.Close() + // Get person name for directory + if strings.TrimSpace(u.dbPath) == "" { http.Redirect(w, r, "/ui/face-gallery", http.StatusFound); return } + repo := storage.NewFaceGalleryRepo(u.dbPath) + persons, _ := repo.ListPersons() + var personName string + for _, p := range persons { if p.ID == id { personName = p.Name; break } } + if personName == "" { http.Error(w, "person not found", http.StatusNotFound); return } + personDir := filepath.Join("dataset", personName) + os.MkdirAll(personDir, 0o755) + dst := filepath.Join(personDir, hdr.Filename) + f, err := os.Create(dst) + if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError); return } + defer f.Close() + io.Copy(f, file) + repo.AddPhoto(id, personName+"/"+hdr.Filename) + 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 196dd6a..8e04005 100644 --- a/internal/web/ui/templates/face_gallery.html +++ b/internal/web/ui/templates/face_gallery.html @@ -15,7 +15,6 @@

{{icon "overview"}}批量导入

-
选择按姓名分目录的照片根目录。
@@ -27,7 +26,6 @@

{{icon "edit"}}新增人员

-
添加单个人员。
@@ -63,15 +61,14 @@ {{end}}
-
- {{.Name}} -
{{.PhotoCount}} 张照片
+ {{.Name}} +
+ + + + +
-t
-
- - -
{{end}} @@ -81,6 +78,24 @@ t
+
+

编辑人员

+ + +
+
+ +
+
+ +
+
+
+
+
+
+ {{end}}