feat: expand full-flow diagnostics

This commit is contained in:
chengma
2026-07-01 15:32:27 +08:00
parent 84b35f1cdc
commit f80f00b5a2
7 changed files with 1085 additions and 53 deletions
+36 -2
View File
@@ -694,6 +694,19 @@ def _notify_collect_step(callback, step):
except Exception:
pass
def _notify_apply_step(callback, step, result="start", detail=None):
if callback is None:
return
payload = {"step": step, "result": result}
if detail:
payload["detail"] = str(detail)
try:
callback(payload)
except Exception:
pass
def _close_collected_product(cdp):
target_id = getattr(cdp, "target_id", None)
created_by_app = bool(getattr(cdp, "created_by_app", False))
@@ -1056,14 +1069,17 @@ def _confirm_update_modal(cdp, timeout=3):
return last_present or {"present": False, "clicked": False, "reason": "NO_UPDATE_CONFIRM_MODAL"}
def apply_task(account, task, close_success_tab=False) -> dict:
def apply_task(account, task, close_success_tab=False, on_step=None) -> dict:
"""Apply generated title/cover to Shopee.
The caller must perform the batch confirmation before calling this function.
"""
item_id = _item_id(task)
current_step = "open_product"
_notify_apply_step(on_step, current_step, "start")
cdp = open_product(account, item_id)
_notify_apply_step(on_step, current_step, "success")
committed = False
try:
title_result = None
@@ -1071,19 +1087,36 @@ def apply_task(account, task, close_success_tab=False) -> dict:
new_title = _get(task, "new_title")
new_cover_path = _get(task, "new_cover_path")
if new_title:
current_step = "change_title"
_notify_apply_step(on_step, current_step, "start")
title_result = change_title(cdp, new_title)
if not title_result.get("ok"):
_notify_apply_step(on_step, current_step, "failed", "标题写入后 value/modelvalue 未同步")
return {"committed": False, "error": "标题写入后 value/modelvalue 未同步", "title": title_result}
_notify_apply_step(on_step, current_step, "success")
if new_cover_path:
current_step = "replace_cover"
_notify_apply_step(on_step, current_step, "start")
cover_result = replace_cover(
cdp,
new_cover_path,
old_cover_path=_get(task, "old_cover_path"),
)
if not cover_result.get("ok"):
return {"committed": False, "error": _cover_upload_error_message(cover_result), "cover": cover_result}
error = _cover_upload_error_message(cover_result)
_notify_apply_step(on_step, current_step, "failed", error)
return {"committed": False, "error": error, "cover": cover_result}
_notify_apply_step(on_step, current_step, "success")
current_step = "click_update"
_notify_apply_step(on_step, current_step, "start")
update_result = click_update(cdp)
committed = bool(update_result.get("clicked", False))
_notify_apply_step(
on_step,
current_step,
"success" if committed else "failed",
update_result.get("reason"),
)
return {
"committed": committed,
"error": update_result.get("reason"),
@@ -1092,6 +1125,7 @@ def apply_task(account, task, close_success_tab=False) -> dict:
"update": update_result,
}
except Exception as exc:
_notify_apply_step(on_step, current_step, "failed", str(exc))
return {"committed": False, "error": str(exc)}
finally:
_close_applied_product(cdp, close_success_tab=close_success_tab and committed)
+760 -34
View File
File diff suppressed because it is too large Load Diff