diff --git a/backend/app.py b/backend/app.py index e7cf0a3..576cfcc 100644 --- a/backend/app.py +++ b/backend/app.py @@ -2409,13 +2409,36 @@ def api_get_recommendation(user_id): """, (now, rec['id'])) conn.commit() + # 제품 이미지 조회 (product_images DB에서 제품명으로 검색) + product_image = None + try: + img_db_path = os.path.join(os.path.dirname(__file__), 'db', 'product_images.db') + img_conn = sqlite3.connect(img_db_path) + img_conn.row_factory = sqlite3.Row + img_cursor = img_conn.cursor() + + product_name = rec['recommended_product'] + # 제품명으로 이미지 검색 (LIKE 검색으로 부분 매칭) + img_cursor.execute(""" + SELECT thumbnail_base64 FROM product_images + WHERE product_name LIKE ? AND thumbnail_base64 IS NOT NULL + LIMIT 1 + """, (f'%{product_name}%',)) + img_row = img_cursor.fetchone() + if img_row: + product_image = img_row['thumbnail_base64'] + img_conn.close() + except Exception as e: + logging.warning(f"[AI추천] 제품 이미지 조회 실패: {e}") + return jsonify({ 'success': True, 'has_recommendation': True, 'recommendation': { 'id': rec['id'], 'product': rec['recommended_product'], - 'message': rec['recommendation_message'] + 'message': rec['recommendation_message'], + 'image': product_image # base64 썸네일 이미지 (없으면 null) } }) diff --git a/backend/templates/my_page.html b/backend/templates/my_page.html index f17e35a..8e4c397 100644 --- a/backend/templates/my_page.html +++ b/backend/templates/my_page.html @@ -466,7 +466,10 @@
-
💊
+
+ +
💊
+
@@ -575,6 +578,17 @@ _recId = data.recommendation.id; document.getElementById('rec-message').textContent = data.recommendation.message; document.getElementById('rec-product').textContent = data.recommendation.product; + + // 제품 이미지 표시 + if (data.recommendation.image) { + document.getElementById('rec-image').src = 'data:image/jpeg;base64,' + data.recommendation.image; + document.getElementById('rec-image').style.display = 'block'; + document.getElementById('rec-emoji').style.display = 'none'; + } else { + document.getElementById('rec-image').style.display = 'none'; + document.getElementById('rec-emoji').style.display = 'block'; + } + document.getElementById('rec-sheet').style.display = 'block'; document.getElementById('rec-backdrop').onclick = dismissRec; }