feat: add root directory files and interactive module - Add account manager, test files, and interactive GUI module; Update requirements.txt

This commit is contained in:
huangzhenpc
2025-02-11 16:10:18 +08:00
parent d82928785d
commit e18297c3c0
12 changed files with 276 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import requests
from typing import Dict, Optional
from config import Config
from logger import logging
import patch_cursor_get_machine_id
class AccountManager:
def __init__(self, api_base_url: str = None):
@@ -69,6 +70,25 @@ class AccountManager:
"Authorization": f"Bearer {self.api_token}"
}
# 确保machine_id不为空
machine_id = account_info.get("machine_id")
if not machine_id:
logging.warning("machine_id为空尝试重新获取")
try:
# 先执行patch操作
patch_cursor_get_machine_id.patch_cursor_get_machine_id()
# 然后获取machine_id
pkg_path, _ = patch_cursor_get_machine_id.get_cursor_paths()
with open(pkg_path, "r", encoding="utf-8") as f:
pkg_data = json.load(f)
machine_id = pkg_data.get("machineId", "")
if machine_id:
logging.info(f"成功获取machine_id: {machine_id}")
except Exception as e:
logging.error(f"获取machine_id失败: {str(e)}")
machine_id = ""
# 准备请求数据
data = {
"email": account_info["email"],
@@ -77,7 +97,7 @@ class AccountManager:
"last_name": account_info["last_name"],
"access_token": account_info["access_token"],
"refresh_token": account_info["refresh_token"],
"machine_id": account_info.get("machine_id", ""),
"machine_id": machine_id,
"user_agent": account_info.get("user_agent", ""),
"registration_time": datetime.fromisoformat(account_info["registration_time"]).strftime("%Y-%m-%d %H:%M:%S")
}
@@ -91,7 +111,7 @@ class AccountManager:
)
response_data = response.json()
if response_data["code"] == 0:
if response_data["code"] == 0 and "添加成功" in response_data.get("msg", ""):
logging.info(f"账号信息已同步到服务器: {account_info['email']}")
return True
elif response_data["code"] == 400: