douyinWEB/scripts/_deploy_dy_oauth_fix.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

102 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy OAuth redirect fix to dy.nomadro.live."""
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "108.174.50.68"
APP = "/opt/douyinWEB"
ROOT = Path(__file__).resolve().parents[1]
FILES = [
"backend/app/main.py",
"backend/app/shorts_oauth.py",
"backend/app/tiktok_oauth.py",
"frontend/src/components/GoogleOauthSetupWizard.tsx",
"frontend/src/app/shorts/page.tsx",
]
PATCH_SH = r"""#!/usr/bin/env bash
set -euo pipefail
source /etc/douyinweb.env
DB="/opt/douyinWEB/backend/data/monitor.db"
REDIRECT="https://dy.nomadro.live/api/shorts/oauth/callback"
TT_REDIRECT="https://dy.nomadro.live/api/tiktok/oauth/callback/"
if [ -f "$DB" ]; then
/opt/douyinWEB/backend/.venv/bin/python - <<PY
import json, sqlite3
db = "/opt/douyinWEB/backend/data/monitor.db"
conn = sqlite3.connect(db)
for key, val in [
("shorts_oauth_redirect_uri", "https://dy.nomadro.live/api/shorts/oauth/callback"),
("tiktok_oauth_redirect_uri", "https://dy.nomadro.live/api/tiktok/oauth/callback/"),
]:
conn.execute(
"INSERT INTO kv_settings(key, value) VALUES (?, ?) "
"ON CONFLICT(key) DO UPDATE SET value=excluded.value",
(key, json.dumps(val)),
)
conn.commit()
conn.close()
print("db redirect updated")
PY
fi
systemctl restart douyinweb-api
sleep 4
cd /opt/douyinWEB/frontend && npm run build
systemctl restart douyinweb-web
sleep 4
curl -sS "http://127.0.0.1:${API_PORT:-8014}/api/shorts/status" | python3 -c "import sys,json; d=json.load(sys.stdin); print('oauth_redirect_uri:', d.get('oauth_redirect_uri'))"
echo DONE
"""
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for rel in FILES:
local = ROOT / rel
remote = f"{APP}/{rel.replace(chr(92), '/')}"
print(f"upload {rel}")
sftp.put(str(local), remote)
sftp.close()
remote = "/tmp/patch_dy_oauth.sh"
sftp = c.open_sftp()
with sftp.file(remote, "w") as f:
f.write(PATCH_SH)
sftp.chmod(remote, 0o755)
sftp.close()
chan = c.get_transport().open_session()
chan.settimeout(600)
chan.get_pty(width=200, height=50)
chan.exec_command(f"bash {remote}")
while True:
if chan.recv_ready():
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
if chan.recv_stderr_ready():
print(chan.recv_stderr(65535).decode("utf-8", "replace"), end="", flush=True)
if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready():
break
time.sleep(0.3)
while chan.recv_ready():
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
code = chan.recv_exit_status()
c.close()
print(f"\nexit {code}")
return code
if __name__ == "__main__":
raise SystemExit(main())