From 48f5f81c44cca74cf97dea12314eeea046668525 Mon Sep 17 00:00:00 2001 From: houhuan Date: Mon, 4 May 2026 22:45:26 +0800 Subject: [PATCH] feat: relocate token storage to script directory and implement NAS synchronization logic --- save_token.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/save_token.py b/save_token.py index 65d6d36..f431d7b 100644 --- a/save_token.py +++ b/save_token.py @@ -42,7 +42,7 @@ async def main(): "micoapi": [ssecurity, service_token], } - token_path = Path.home() / ".mi.token" + token_path = Path(__file__).resolve().parent / ".mi.token" token_path.write_text(json.dumps(token, ensure_ascii=False, indent=2), encoding="utf-8") print(f"Token saved to {token_path}") print(f" userId: {USER_ID}") @@ -50,4 +50,21 @@ async def main(): print(f" ssecurity: OK") print(f" serviceToken: OK ({service_token[:30]}...)") + # --- 新增推送至 NAS 逻辑 --- + nas_url = "http://5kan.cc:42000/sync" + headers = {"X-Auth-Key": "my_private_key_123"} # 注意:请确保与服务器端的 SECRET_KEY 一致 + + print(f"\n正在同步至 NAS ({nas_url})...") + try: + async with s.post(nas_url, json=token, headers=headers, timeout=15) as resp: + if resp.status == 200: + result = await resp.json() + print(f"✅ NAS 同步成功: {result.get('msg')}") + else: + text = await resp.text() + print(f"❌ NAS 同步失败 (状态码 {resp.status}): {text}") + except Exception as e: + print(f"❌ 无法连接到 NAS: {e}") + print("请检查:1. 宝塔是否放行 42000 端口;2. 路由器是否做了端口转发;3. 接收端脚本是否正在运行。") + asyncio.run(main())