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