nomadro/apps/admin/deploy/_hotfix_tt_config.py
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

76 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Hotfix tt_platform_config.py and verify /api/admin/douyin/config."""
from __future__ import annotations
import time
from pathlib import Path
import paramiko
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
LOCAL = Path(__file__).resolve().parents[1] / "backend" / "app" / "services" / "tt_platform_config.py"
REMOTE = "/opt/nomadmini/backend/app/services/tt_platform_config.py"
def main() -> int:
text = LOCAL.read_text(encoding="utf-8")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/tt_platform_config.py", "w") as f:
f.write(text)
sftp.close()
cmd = r"""
set -e
sudo cp /tmp/tt_platform_config.py /opt/nomadmini/backend/app/services/tt_platform_config.py
sudo chown ubuntu:ubuntu /opt/nomadmini/backend/app/services/tt_platform_config.py
# also copy seed book if missing
if [ ! -f /opt/nomadmini/backend/data/tt-default-book.json ] && [ -f /var/www/nomadro.cn/lib/tt-default-book.json ]; then
sudo mkdir -p /opt/nomadmini/backend/data
sudo cp /var/www/nomadro.cn/lib/tt-default-book.json /opt/nomadmini/backend/data/
fi
sudo systemctl restart nomadmini-api
sleep 2
systemctl is-active nomadmini-api
cd /opt/nomadmini/backend && .venv/bin/python - <<'PY'
from app.services.tt_platform_config import read_tt_platform, resolve_config_file
print('file', resolve_config_file())
cfg = read_tt_platform()
print('modules', {k: v.get('enabled') for k,v in (cfg.get('modules') or {}).items()})
print('chapters', len((cfg.get('bookContent') or {}).get('chapters') or []))
PY
# login then hit config
TOKEN=$(curl -sk -X POST https://admin.nomadro.cn/api/admin/login \
-H 'Content-Type: application/json' \
-d '{"username":"admin","password":"Xiao4669805"}' | python3 -c 'import sys,json; print(json.load(sys.stdin).get("token") or json.load(open("/dev/stdin")).get("access_token",""))' 2>/dev/null || true)
# try common login shapes
if [ -z "$TOKEN" ]; then
BODY=$(curl -sk -X POST https://admin.nomadro.cn/api/admin/login -H 'Content-Type: application/json' -d '{"username":"admin","password":"Xiao4669805"}')
echo "login_body=$BODY"
TOKEN=$(echo "$BODY" | python3 -c 'import sys,json; d=json.load(sys.stdin); print(d.get("token") or d.get("access_token") or "")')
fi
echo "token_len=${#TOKEN}"
if [ -n "$TOKEN" ]; then
curl -sk -H "Authorization: Bearer $TOKEN" https://admin.nomadro.cn/api/admin/douyin/config | python3 -c 'import sys,json; d=json.load(sys.stdin); print("config_ok", d.get("ok"), "mods", list((d.get("config") or {}).get("modules") or {}).keys())'
else
curl -sk -o /dev/null -w "config_noauth %{http_code}\n" https://admin.nomadro.cn/api/admin/douyin/config
fi
"""
_, stdout, _ = c.exec_command(cmd, timeout=120, get_pty=True)
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
time.sleep(0.05)
while stdout.channel.recv_ready():
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
code = stdout.channel.recv_exit_status()
print(f"[exit {code}]", flush=True)
c.close()
return code
if __name__ == "__main__":
raise SystemExit(main())