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 @@