From 4a3ec38ba7d82403d7e9f917a87b65497af1735f Mon Sep 17 00:00:00 2001 From: thug0bin Date: Mon, 2 Mar 2026 23:47:11 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EA=B5=90?= =?UTF-8?q?=EC=B2=B4=20=EC=8B=9C=20=EB=B0=94=EC=BD=94=EB=93=9C=20=EC=A0=84?= =?UTF-8?q?=EB=8B=AC=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - data 속성으로 바코드/제품명 전달 (escapeHtml 문제 해결) - 기존 레코드 유지하도록 UPDATE 쿼리 수정 --- backend/app.py | 23 +++++++++++++-------- backend/templates/admin_product_images.html | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend/app.py b/backend/app.py index 3b26ab8..e7cf0a3 100644 --- a/backend/app.py +++ b/backend/app.py @@ -5862,20 +5862,25 @@ def api_replace_product_image(barcode): except Exception as e: return jsonify({'success': False, 'error': f'이미지 처리 실패: {str(e)}'}), 400 - # SQLite 업데이트 + # SQLite 업데이트 (기존 값 유지) db_path = os.path.join(os.path.dirname(__file__), 'db', 'product_images.db') conn = sqlite3.connect(db_path) cursor = conn.cursor() - cursor.execute(""" - UPDATE product_images - SET image_base64 = ?, thumbnail_base64 = ?, image_url = ?, - status = 'manual', error_message = NULL, updated_at = datetime('now') - WHERE barcode = ? - """, (image_base64, thumbnail_base64, image_url, barcode)) + # 기존 레코드 확인 + cursor.execute("SELECT product_name, drug_code FROM product_images WHERE barcode = ?", (barcode,)) + existing = cursor.fetchone() - if cursor.rowcount == 0: - # 레코드가 없으면 새로 생성 + if existing: + # 기존 레코드 있으면 이미지만 업데이트 (product_name, drug_code 유지) + cursor.execute(""" + UPDATE product_images + SET image_base64 = ?, thumbnail_base64 = ?, image_url = ?, + status = 'manual', error_message = NULL, updated_at = datetime('now') + WHERE barcode = ? + """, (image_base64, thumbnail_base64, image_url, barcode)) + else: + # 레코드가 없으면 새로 생성 (product_name은 barcode로 임시 저장) cursor.execute(""" INSERT INTO product_images (barcode, image_base64, thumbnail_base64, image_url, status, product_name) VALUES (?, ?, ?, ?, 'manual', ?) diff --git a/backend/templates/admin_product_images.html b/backend/templates/admin_product_images.html index efac690..e3abe8d 100644 --- a/backend/templates/admin_product_images.html +++ b/backend/templates/admin_product_images.html @@ -504,7 +504,7 @@ ${getStatusText(item.status)}
- +