Fix kdocs upload status restore
This commit is contained in:
@@ -647,6 +647,11 @@ class KDocsUploader:
|
||||
if not image_path or not os.path.exists(image_path):
|
||||
return
|
||||
|
||||
account = None
|
||||
prev_status = None
|
||||
status_tracked = False
|
||||
|
||||
try:
|
||||
if not self._ensure_playwright():
|
||||
self._notify_admin(unit, name, image_path, self._last_error or "浏览器不可用")
|
||||
return
|
||||
@@ -659,19 +664,21 @@ class KDocsUploader:
|
||||
self._login_required = True
|
||||
self._last_login_ok = False
|
||||
self._notify_admin(unit, name, image_path, "登录已失效,请管理员重新扫码登录")
|
||||
try:
|
||||
log_to_client("表格上传失败: 登录已失效,请管理员重新扫码登录", user_id, account_id)
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
self._login_required = False
|
||||
self._last_login_ok = True
|
||||
|
||||
prev_status = None
|
||||
account = None
|
||||
try:
|
||||
account = safe_get_account(user_id, account_id)
|
||||
if account and not getattr(account, "is_running", False):
|
||||
prev_status = getattr(account, "status", None)
|
||||
account.status = "上传截图"
|
||||
self._emit_account_update(user_id, account)
|
||||
status_tracked = True
|
||||
except Exception:
|
||||
prev_status = None
|
||||
|
||||
@@ -699,15 +706,22 @@ class KDocsUploader:
|
||||
if success:
|
||||
self._last_success_at = time.time()
|
||||
self._last_error = None
|
||||
try:
|
||||
log_to_client(f"已上传表格截图: {unit}-{name}", user_id, account_id)
|
||||
self._restore_account_status(user_id, account, prev_status)
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
|
||||
if not error_msg:
|
||||
error_msg = "上传失败"
|
||||
self._last_error = error_msg
|
||||
self._notify_admin(unit, name, image_path, error_msg)
|
||||
try:
|
||||
log_to_client(f"表格上传失败: {error_msg}", user_id, account_id)
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
if status_tracked:
|
||||
self._restore_account_status(user_id, account, prev_status)
|
||||
|
||||
def _notify_admin(self, unit: str, name: str, image_path: str, error: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user