feat: 마이페이지 AI 추천에 제품 이미지 표시

- /api/recommendation API에서 product_images DB 조회
- 제품명 매칭으로 썸네일 이미지 반환
- 이미지 있으면 실제 사진, 없으면 💊 이모지 표시
This commit is contained in:
thug0bin 2026-03-03 00:02:04 +09:00
parent 95fdd23817
commit 8aa43221d2
2 changed files with 39 additions and 2 deletions

View File

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

View File

@ -466,7 +466,10 @@
</div>
<div style="padding:0 24px 32px;">
<div style="text-align:center;padding:8px 0 20px;">
<div style="font-size:48px;margin-bottom:16px;">💊</div>
<div id="rec-image-container" style="margin-bottom:16px;">
<img id="rec-image" style="width:100px;height:100px;object-fit:contain;border-radius:12px;display:none;" alt="추천 제품">
<div id="rec-emoji" style="font-size:48px;">💊</div>
</div>
<div id="rec-message" style="color:#343a40;font-size:16px;font-weight:500;line-height:1.6;letter-spacing:-0.3px;margin-bottom:16px;"></div>
<div id="rec-product" style="display:inline-block;background:linear-gradient(135deg,#6366f1,#8b5cf6);color:#fff;font-size:14px;font-weight:600;padding:8px 20px;border-radius:20px;letter-spacing:-0.2px;"></div>
</div>
@ -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;
}