fix: 이미지 교체 시 바코드 전달 오류 수정

- data 속성으로 바코드/제품명 전달 (escapeHtml 문제 해결)
- 기존 레코드 유지하도록 UPDATE 쿼리 수정
This commit is contained in:
thug0bin 2026-03-02 23:47:11 +09:00
parent 4a06e60e29
commit 4a3ec38ba7
2 changed files with 15 additions and 10 deletions

View File

@ -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', ?)

View File

@ -504,7 +504,7 @@
<span class="status ${item.status}">${getStatusText(item.status)}</span>
<div class="actions">
<button class="btn btn-secondary btn-sm" onclick="viewDetail('${item.barcode}')">상세</button>
<button class="btn btn-primary btn-sm" onclick="openReplaceModal('${item.barcode}', '${escapeHtml(item.product_name)}')">교체</button>
<button class="btn btn-primary btn-sm" data-barcode="${item.barcode}" data-name="${item.product_name || ''}" onclick="openReplaceModal(this.dataset.barcode, this.dataset.name)">교체</button>
<button class="btn btn-danger btn-sm" onclick="deleteImage('${item.barcode}')">삭제</button>
</div>
</div>