mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-07-09 06:21:23 +08:00
fix(log): 修复
This commit is contained in:
@@ -154,9 +154,9 @@ class RegistrationEngine:
|
|||||||
logger.warning(f"记录任务日志失败: {e}")
|
logger.warning(f"记录任务日志失败: {e}")
|
||||||
|
|
||||||
# 根据级别记录到日志系统
|
# 根据级别记录到日志系统
|
||||||
if level == "error":
|
if level == 'error':
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
elif level == "warning":
|
elif level == 'warning':
|
||||||
logger.warning(message)
|
logger.warning(message)
|
||||||
else:
|
else:
|
||||||
logger.info(message)
|
logger.info(message)
|
||||||
@@ -170,7 +170,7 @@ class RegistrationEngine:
|
|||||||
try:
|
try:
|
||||||
return self.http_client.check_ip_location()
|
return self.http_client.check_ip_location()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"检查 IP 地理位置失败: {e}", "error")
|
self._log(f"检查 IP 地理位置失败: {e}", 'error')
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
def _create_email(self) -> bool:
|
def _create_email(self) -> bool:
|
||||||
@@ -180,7 +180,7 @@ class RegistrationEngine:
|
|||||||
self.email_info = self.email_service.create_email()
|
self.email_info = self.email_service.create_email()
|
||||||
|
|
||||||
if not self.email_info or "email" not in self.email_info:
|
if not self.email_info or "email" not in self.email_info:
|
||||||
self._log("创建邮箱失败: 返回信息不完整", "error")
|
self._log("创建邮箱失败: 返回信息不完整", 'error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.email = self.email_info["email"]
|
self.email = self.email_info["email"]
|
||||||
@@ -188,7 +188,7 @@ class RegistrationEngine:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"创建邮箱失败: {e}", "error")
|
self._log(f"创建邮箱失败: {e}", 'error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _start_oauth(self) -> bool:
|
def _start_oauth(self) -> bool:
|
||||||
@@ -199,7 +199,7 @@ class RegistrationEngine:
|
|||||||
self._log(f"OAuth URL 已生成: {self.oauth_start.auth_url[:80]}...")
|
self._log(f"OAuth URL 已生成: {self.oauth_start.auth_url[:80]}...")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"生成 OAuth URL 失败: {e}", "error")
|
self._log(f"生成 OAuth URL 失败: {e}", 'error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _init_session(self) -> bool:
|
def _init_session(self) -> bool:
|
||||||
@@ -208,7 +208,7 @@ class RegistrationEngine:
|
|||||||
self.session = self.http_client.session
|
self.session = self.http_client.session
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"初始化会话失败: {e}", "error")
|
self._log(f"初始化会话失败: {e}", 'error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_device_id(self) -> Optional[str]:
|
def _get_device_id(self) -> Optional[str]:
|
||||||
@@ -234,12 +234,12 @@ class RegistrationEngine:
|
|||||||
|
|
||||||
self._log(
|
self._log(
|
||||||
f"获取 Device ID 失败: 未返回 oai-did Cookie (HTTP {response.status_code}, 第 {attempt}/{max_attempts} 次)",
|
f"获取 Device ID 失败: 未返回 oai-did Cookie (HTTP {response.status_code}, 第 {attempt}/{max_attempts} 次)",
|
||||||
"warning" if attempt < max_attempts else "error"
|
'warning' if attempt < max_attempts else 'error'
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(
|
self._log(
|
||||||
f"获取 Device ID 失败: {e} (第 {attempt}/{max_attempts} 次)",
|
f"获取 Device ID 失败: {e} (第 {attempt}/{max_attempts} 次)",
|
||||||
"warning" if attempt < max_attempts else "error"
|
'warning' if attempt < max_attempts else 'error'
|
||||||
)
|
)
|
||||||
|
|
||||||
if attempt < max_attempts:
|
if attempt < max_attempts:
|
||||||
@@ -269,11 +269,11 @@ class RegistrationEngine:
|
|||||||
self._log(f"Sentinel token 获取成功")
|
self._log(f"Sentinel token 获取成功")
|
||||||
return sen_token
|
return sen_token
|
||||||
else:
|
else:
|
||||||
self._log(f"Sentinel 检查失败: {response.status_code}", "warning")
|
self._log(f"Sentinel 检查失败: {response.status_code}", 'warning')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"Sentinel 检查异常: {e}", "warning")
|
self._log(f"Sentinel 检查异常: {e}", 'warning')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _submit_signup_form(self, did: str, sen_token: Optional[str]) -> SignupFormResult:
|
def _submit_signup_form(self, did: str, sen_token: Optional[str]) -> SignupFormResult:
|
||||||
@@ -332,12 +332,12 @@ class RegistrationEngine:
|
|||||||
)
|
)
|
||||||
|
|
||||||
except Exception as parse_error:
|
except Exception as parse_error:
|
||||||
self._log(f"解析响应失败: {parse_error}", "warning")
|
self._log(f"解析响应失败: {parse_error}", 'warning')
|
||||||
# 无法解析,默认成功
|
# 无法解析,默认成功
|
||||||
return SignupFormResult(success=True)
|
return SignupFormResult(success=True)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"提交注册表单失败: {e}", "error")
|
self._log(f"提交注册表单失败: {e}", 'error')
|
||||||
return SignupFormResult(success=False, error_message=str(e))
|
return SignupFormResult(success=False, error_message=str(e))
|
||||||
|
|
||||||
def _register_password(self) -> Tuple[bool, Optional[str]]:
|
def _register_password(self) -> Tuple[bool, Optional[str]]:
|
||||||
@@ -367,17 +367,17 @@ class RegistrationEngine:
|
|||||||
self._log(f"提交密码状态: {response.status_code}")
|
self._log(f"提交密码状态: {response.status_code}")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
self._log(f"密码注册失败: {response.json().get("error", {}).get("message", "")}", "warning")
|
self._log(f"密码注册失败: {response.json().get('error', {}).get('message', "")}", 'warning')
|
||||||
|
|
||||||
# 解析错误信息,判断是否是邮箱已注册
|
# 解析错误信息,判断是否是邮箱已注册
|
||||||
try:
|
try:
|
||||||
error_json = response.json()
|
error_json = response.json()
|
||||||
error_msg = error_json.get("error", {}).get("message", "")
|
error_msg = error_json.get('error', {}).get('message', "")
|
||||||
error_code = error_json.get("error", {}).get("code", "")
|
error_code = error_json.get('error', {}).get('code', "")
|
||||||
|
|
||||||
# 检测邮箱已注册的情况
|
# 检测邮箱已注册的情况
|
||||||
if "already" in error_msg.lower() or "exists" in error_msg.lower() or "again" in error_msg.lower() or error_code == "user_exists" or error_code == "invalid_request":
|
if "already" in error_msg.lower() or "exists" in error_msg.lower() or "again" in error_msg.lower() or error_code == "user_exists" or error_code == "invalid_request":
|
||||||
self._log(f"邮箱 {self.email} 可能已在 OpenAI 注册过", "error")
|
self._log(f"邮箱 {self.email} 可能已在 OpenAI 注册过", 'error')
|
||||||
# 标记此邮箱为已注册状态
|
# 标记此邮箱为已注册状态
|
||||||
self._mark_email_as_registered()
|
self._mark_email_as_registered()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -388,7 +388,7 @@ class RegistrationEngine:
|
|||||||
return True, password
|
return True, password
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"密码注册失败: {e}", "error")
|
self._log(f"密码注册失败: {e}", 'error')
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
|
|
||||||
@@ -441,7 +441,7 @@ class RegistrationEngine:
|
|||||||
return response.status_code == 200
|
return response.status_code == 200
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"发送验证码失败: {e}", "error")
|
self._log(f"发送验证码失败: {e}", 'error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_verification_code(self) -> Optional[str]:
|
def _get_verification_code(self) -> Optional[str]:
|
||||||
@@ -462,11 +462,11 @@ class RegistrationEngine:
|
|||||||
self._log(f"成功获取验证码: {code}")
|
self._log(f"成功获取验证码: {code}")
|
||||||
return code
|
return code
|
||||||
else:
|
else:
|
||||||
self._log("等待验证码超时", "error")
|
self._log("等待验证码超时", 'error')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"获取验证码失败: {e}", "error")
|
self._log(f"获取验证码失败: {e}", 'error')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _validate_verification_code(self, code: str) -> bool:
|
def _validate_verification_code(self, code: str) -> bool:
|
||||||
@@ -488,7 +488,7 @@ class RegistrationEngine:
|
|||||||
return response.status_code == 200
|
return response.status_code == 200
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"验证验证码失败: {e}", "error")
|
self._log(f"验证验证码失败: {e}", 'error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _create_user_account(self) -> bool:
|
def _create_user_account(self) -> bool:
|
||||||
@@ -511,13 +511,13 @@ class RegistrationEngine:
|
|||||||
self._log(f"账户创建状态: {response.status_code}")
|
self._log(f"账户创建状态: {response.status_code}")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
self._log(f"账户创建失败: {response.text[:200]}", "warning")
|
self._log(f"账户创建失败: {response.text[:200]}", 'warning')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"创建账户失败: {e}", "error")
|
self._log(f"创建账户失败: {e}", 'error')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _add_phone(self) -> bool:
|
def _add_phone(self) -> bool:
|
||||||
@@ -574,5 +574,5 @@ class RegistrationEngine:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(f"保存到数据库失败: {e}", "error")
|
self._log(f"保存到数据库失败: {e}", 'error')
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -1049,7 +1049,6 @@ function resetButtons() {
|
|||||||
elements.cancelBtn.disabled = true;
|
elements.cancelBtn.disabled = true;
|
||||||
currentTask = null;
|
currentTask = null;
|
||||||
currentBatch = null;
|
currentBatch = null;
|
||||||
isBatchMode = false;
|
|
||||||
// 重置完成标志
|
// 重置完成标志
|
||||||
taskCompleted = false;
|
taskCompleted = false;
|
||||||
batchCompleted = false;
|
batchCompleted = false;
|
||||||
@@ -1275,12 +1274,13 @@ function connectBatchWebSocket(batchId) {
|
|||||||
if (!toastShown) {
|
if (!toastShown) {
|
||||||
toastShown = true;
|
toastShown = true;
|
||||||
if (data.status === 'completed') {
|
if (data.status === 'completed') {
|
||||||
addLog('success', `[完成] Outlook 批量任务完成!成功: ${data.success}, 失败: ${data.failed}, 跳过: ${data.skipped || 0}`);
|
const batchLabel = isOutlookBatchMode ? 'Outlook 批量' : '批量';
|
||||||
|
addLog('success', `[完成] ${batchLabel}任务完成!成功: ${data.success}, 失败: ${data.failed}, 跳过: ${data.skipped || 0}`);
|
||||||
if (data.success > 0) {
|
if (data.success > 0) {
|
||||||
toast.success(`Outlook 批量注册完成,成功 ${data.success} 个`);
|
toast.success(`${batchLabel}注册完成,成功 ${data.success} 个`);
|
||||||
loadRecentAccounts();
|
loadRecentAccounts();
|
||||||
} else {
|
} else {
|
||||||
toast.warning('Outlook 批量注册完成,但没有成功注册任何账号');
|
toast.warning(`${batchLabel}注册完成,但没有成功注册任何账号`);
|
||||||
}
|
}
|
||||||
} else if (data.status === 'failed') {
|
} else if (data.status === 'failed') {
|
||||||
addLog('error', '[错误] 批量任务执行失败');
|
addLog('error', '[错误] 批量任务执行失败');
|
||||||
|
|||||||
Reference in New Issue
Block a user