# -*- 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 - < 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())