douyinWEB/scripts/_deploy_oauth_debug.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

62 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy OAuth debug + same-tab auth fix."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
VPS = "107.173.30.245"
PORT, USER, PW = 4014, "eric", "4669805"
def main():
g = paramiko.SSHClient()
g.set_missing_host_key_policy(paramiko.AutoAddPolicy())
g.connect(VPS, PORT, USER, PW, timeout=40, banner_timeout=80, allow_agent=False, look_for_keys=False)
sftp = g.open_sftp()
sftp.put(str(ROOT / "backend/app/shorts_oauth.py"), "/tmp/_up_shorts_oauth.py")
sftp.put(str(ROOT / "frontend/src/app/shorts/page.tsx"), "/tmp/_up_shorts_page.tsx")
sftp.close()
cmd = rf"""
echo '{PW}' | sudo -S -p '' bash -lc '
set -e
install -m 644 /tmp/_up_shorts_oauth.py /opt/douyinWEB/backend/app/shorts_oauth.py
install -m 644 /tmp/_up_shorts_page.tsx /opt/douyinWEB/frontend/src/app/shorts/page.tsx
cd /opt/douyinWEB/backend && .venv/bin/python -m py_compile app/shorts_oauth.py
systemctl restart douyinweb-api
# FE rebuild for same-tab oauth
systemctl stop douyinweb-web || true
cd /opt/douyinWEB/frontend
npm run build >/tmp/shorts_oauth_fe_build.log 2>&1
tail -20 /tmp/shorts_oauth_fe_build.log
systemctl start douyinweb-web
for i in $(seq 1 20); do
c=$(curl -sS -m 3 -o /dev/null -w "%{{http_code}}" http://127.0.0.1:8014/api/health || echo x)
echo api $c
[ "$c" = "200" ] && break
sleep 2
done
curl -sS -m 3 -o /dev/null -w "web:%{{http_code}}\n" http://127.0.0.1:4015/login || true
# show current channel
cd /opt/douyinWEB/backend && .venv/bin/python - <<PY
from app import db
for c in db.list_shorts_channels():
print(c.get("id"), c.get("name"), c.get("oauth_error"), "rt", bool(c.get("refresh_token")))
PY
'
"""
_, o, e = g.exec_command(cmd, timeout=600)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
g.close()
if __name__ == "__main__":
main()