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

77 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy OAuth email scope + Gmail display."""
from __future__ import annotations
import sys
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
HOST = "108.174.50.68"
PASS = "Xiao4669805"
REPO = "/opt/douyinWEB"
FILES = [
"backend/app/shorts_oauth.py",
"backend/app/db.py",
"frontend/src/app/settings/page.tsx",
"frontend/src/app/shorts/page.tsx",
"frontend/src/components/OauthClientBadge.tsx",
]
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", PASS, timeout=60, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for rel in FILES:
sftp.put(str(ROOT / rel), f"{REPO}/{rel}")
print("uploaded", rel)
sftp.close()
cmd = r"""
set -e
systemctl restart douyinweb-api
cd /opt/douyinWEB/frontend && npm run build
systemctl restart douyinweb-web
sleep 2
systemctl is-active douyinweb-api douyinweb-web
cd /opt/douyinWEB/backend
PYTHONPATH=. .venv/bin/python - <<'PY'
from app import db, shorts_oauth
db.init_db()
assert 'openid' in shorts_oauth.authorize_scopes()
assert 'email' in shorts_oauth.authorize_scopes()
assert 'email' not in ' '.join(shorts_oauth.requested_scopes()) # not required for oauth_ok
assert hasattr(shorts_oauth, 'fetch_google_account_email')
assert hasattr(shorts_oauth, 'set_oauth_profile_email')
# column exists
conn = db._connect()
cols = {r[1] for r in conn.execute('PRAGMA table_info(shorts_channels)').fetchall()}
assert 'oauth_email' in cols
conn.close()
pubs = shorts_oauth.list_oauth_profiles(public=True)
print('profiles', [(p.get('id'), p.get('email') or '') for p in pubs])
print('ok')
PY
"""
print("deploy…")
_i, o, e = c.exec_command(cmd, timeout=360)
out = o.read().decode("utf-8", "replace")
err = e.read().decode("utf-8", "replace")
code = o.channel.recv_exit_status()
print(out[-3500:] if len(out) > 3500 else out)
if err.strip():
print("STDERR", err[-1500:])
print("exit", code)
c.close()
return code
if __name__ == "__main__":
raise SystemExit(main())