From 85c3095e987553f4df3d7bffce0728d78fe54b5a Mon Sep 17 00:00:00 2001 From: huangzhenpc Date: Mon, 7 Apr 2025 15:13:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=8E=B0=E6=9C=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20=E5=A2=9E=E5=8A=A0=E5=9F=9F=E5=90=8D=E5=92=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_cursor_service.py | 89 ++++++++++++++++++++++++++---------------- main.py | 22 ++++++++--- 2 files changed, 72 insertions(+), 39 deletions(-) diff --git a/auto_cursor_service.py b/auto_cursor_service.py index b3e17f3..6e51c9a 100644 --- a/auto_cursor_service.py +++ b/auto_cursor_service.py @@ -385,42 +385,63 @@ class AutoCursorService: self.registration_process = None - async def upload_accounts(self): - """上传已注册成功的账号""" - logger.info("开始上传注册成功的账号") - try: - # 使用subprocess运行upload_account.py - if sys.platform.startswith("win"): - process = subprocess.Popen( - ["python", "upload_account.py"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - creationflags=subprocess.CREATE_NO_WINDOW - ) - else: - process = subprocess.Popen( - ["python3", "upload_account.py"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE - ) - - # 等待进程完成 - stdout, stderr = process.communicate() - - if process.returncode != 0: - logger.error(f"上传账号进程异常终止,退出码: {process.returncode}") - if stderr: - logger.error(f"错误输出: {stderr.decode('utf-8', errors='ignore')}") - else: - logger.info("账号上传完成") - if stdout: - # 只记录最后几行输出 - output_lines = stdout.decode('utf-8', errors='ignore').strip().split('\n') - for line in output_lines[-5:]: - logger.info(f"Upload: {line}") + async def upload_accounts(self, accounts: List[Dict[str, Any]]) -> bool: + """上传账号到API + Args: + accounts: 要上传的账号列表,每个账号包含email、password、cursor_password等信息 + + Returns: + bool: 是否上传成功 + """ + if not accounts: + return True + + url = f"{self.api_base_url}/commonadd" + + try: + # 准备上传数据 + upload_data = [] + for account in accounts: + upload_item = { + "email": account["email"], + "email_password": account["password"], # 使用password作为email_password + "cursor_email": account["email"], + "cursor_password": account["cursor_password"], + "cookie": account["cursor_cookie"] or "", + "token": account.get("cursor_jwt", ""), # 使用cursor_jwt作为token + "hostname": self.hostname + } + upload_data.append(upload_item) + + logger.debug(f"准备上传 {len(upload_data)} 个账号") + + # 发送请求 + async with aiohttp.ClientSession() as session: + async with session.post( + url, + json=upload_data, + proxy=self.proxy, + ssl=False + ) as response: + if response.status != 200: + logger.error(f"上传账号API请求失败,状态码: {response.status}") + return False + + data = await response.json() + if data.get("code") != 0: + logger.error(f"上传账号API返回错误: {data.get('msg', 'Unknown error')}") + return False + + success_count = data.get("data", {}).get("success", 0) + failed_count = data.get("data", {}).get("failed", 0) + logger.info(f"账号上传结果: 成功 {success_count}, 失败 {failed_count}") + + return success_count > 0 + except Exception as e: - logger.error(f"执行账号上传脚本时出错: {e}") + logger.error(f"上传账号时出错: {e}") + return False async def run(self): """运行服务主循环""" diff --git a/main.py b/main.py index 4dbae3d..69bf6f8 100644 --- a/main.py +++ b/main.py @@ -18,6 +18,7 @@ from services.proxy_pool import ProxyPool from services.token_pool import TokenPool from services.self_hosted_email import SelfHostedEmail from upload_account import AccountUploader +from auto_cursor_service import AutoCursorService class CursorRegister: @@ -208,12 +209,23 @@ class CursorRegister: skipped += 1 else: successful.append(result) + # 添加详细的账号信息日志 + self.logger.info("=" * 50) + self.logger.info(f"账号 {i+1} 注册成功:") + self.logger.info(f"邮箱: {result['email']}") + self.logger.info(f"邮箱密码: {result['email_password']}") + self.logger.info(f"Cursor密码: {result['cursor_password']}") + # 只显示token的前30个字符,避免日志过长 + token = result.get('cursor_jwt', '') + if token: + self.logger.info(f"Token: {token[:30]}...") + self.logger.info("=" * 50) # 6. 直接上传成功注册的账号 if successful: try: - uploader = AccountUploader() - await uploader.initialize() + service = AutoCursorService() + await service.initialize() # 准备上传数据 upload_data = [] @@ -223,13 +235,13 @@ class CursorRegister: "password": account["email_password"], "cursor_password": account["cursor_password"], "cursor_cookie": account["cursor_cookie"], - "cursor_token": account.get("cursor_jwt", "") + "cursor_jwt": account.get("cursor_jwt", "") } upload_data.append(upload_item) # 上传账号 - await uploader.upload_accounts(upload_data) - await uploader.cleanup() + await service.upload_accounts(upload_data) + await service.cleanup() self.logger.info(f"成功上传 {len(upload_data)} 个账号到服务器") except Exception as e: self.logger.error(f"上传账号时发生错误: {str(e)}")