feat: relocate token storage to script directory and implement NAS synchronization logic
This commit is contained in:
+18
-1
@@ -42,7 +42,7 @@ async def main():
|
|||||||
"micoapi": [ssecurity, service_token],
|
"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")
|
token_path.write_text(json.dumps(token, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||||
print(f"Token saved to {token_path}")
|
print(f"Token saved to {token_path}")
|
||||||
print(f" userId: {USER_ID}")
|
print(f" userId: {USER_ID}")
|
||||||
@@ -50,4 +50,21 @@ async def main():
|
|||||||
print(f" ssecurity: OK")
|
print(f" ssecurity: OK")
|
||||||
print(f" serviceToken: OK ({service_token[:30]}...)")
|
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())
|
asyncio.run(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user