|
|
@@ -203,6 +203,32 @@ async def _update_card_scores(card_id: int) -> None:
|
|
|
logger.error("更新卡牌分数失败 card_id=%s error=%s", card_id, e, exc_info=True)
|
|
|
|
|
|
|
|
|
+async def _notify_rating_progress(cardNo: Optional[str], headers: Optional[Dict[str, str]] = None) -> bool:
|
|
|
+ if not cardNo:
|
|
|
+ logger.info("Skip rating progress notify because cardNo is empty")
|
|
|
+ return False
|
|
|
+
|
|
|
+ url = (settings.RATING_SAVE_PROGRESS or "").strip()
|
|
|
+ if not url:
|
|
|
+ logger.info("Skip rating progress notify because RATING_SAVE_PROGRESS is empty")
|
|
|
+ return False
|
|
|
+
|
|
|
+ notify_headers = {}
|
|
|
+ if headers and headers.get("Authorization"):
|
|
|
+ notify_headers["Authorization"] = headers["Authorization"]
|
|
|
+
|
|
|
+ timeout = aiohttp.ClientTimeout(total=3, connect=1, sock_connect=1, sock_read=2)
|
|
|
+ try:
|
|
|
+ async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
|
+ async with session.post(url, json={"cardNo": cardNo}, headers=notify_headers or None) as resp:
|
|
|
+ resp_text = await resp.text()
|
|
|
+ logger.info("Save rating progress: status=%s body=%s", resp.status, resp_text[:500])
|
|
|
+ return resp.status == 200
|
|
|
+ except Exception as e:
|
|
|
+ logger.error("Save rating progress failed cardNo=%s error=%s", cardNo, e, exc_info=True)
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
def _resolve_internal_base_url(request: Request) -> str:
|
|
|
"""
|
|
|
导入流程内部调用本服务时优先走集群内地址,避免经 ingress 再次鉴权导致 401。
|
|
|
@@ -899,7 +925,7 @@ async def auto_import_url_script_api(
|
|
|
bytes_map[image_type] = (file_bytes, filename)
|
|
|
|
|
|
try:
|
|
|
- return await _run_import_flow(
|
|
|
+ result = await _run_import_flow(
|
|
|
local_base_url=local_base_url,
|
|
|
card_name=card_name,
|
|
|
cardNo=cardNo,
|
|
|
@@ -910,6 +936,10 @@ async def auto_import_url_script_api(
|
|
|
non_gray_to_main=True,
|
|
|
forward_headers=forward_headers or None,
|
|
|
)
|
|
|
+ progress_saved = await _notify_rating_progress(cardNo, forward_headers or None)
|
|
|
+ if not progress_saved:
|
|
|
+ result["message"] = "导入算分服务成功, 但记录进度失败"
|
|
|
+ return result
|
|
|
except HTTPException:
|
|
|
raise
|
|
|
except Exception as e:
|