From f8d1083b2d28c9e65d01f76157fb61c5d4bccdba Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 8 May 2026 12:53:06 +0800 Subject: [PATCH] fix: check duplicate photo in AddPhoto --- internal/storage/face_gallery_repo.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/storage/face_gallery_repo.go b/internal/storage/face_gallery_repo.go index 5e62bc5..635016d 100644 --- a/internal/storage/face_gallery_repo.go +++ b/internal/storage/face_gallery_repo.go @@ -112,6 +112,11 @@ func (r *FaceGalleryRepo) AddPhoto(personID int, photoPath string) error { return err } defer db.Close() + // Skip if already exists + var existing int + if db.QueryRow(`SELECT COUNT(*) FROM face_photos WHERE person_id = ? AND photo_path = ?`, personID, photoPath).Scan(&existing) == nil && existing > 0 { + return nil + } now := time.Now().Format(time.RFC3339) _, err = db.Exec(`INSERT INTO face_photos(person_id, photo_path, created_at) VALUES(?, ?, ?)`, personID, photoPath, now) return err