保存现有功能 增加域名和添加时间关联

This commit is contained in:
huangzhenpc
2025-04-07 15:13:07 +08:00
parent 69bf430525
commit 85c3095e98
2 changed files with 72 additions and 39 deletions

View File

@@ -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):
"""运行服务主循环"""