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