douyinWEB/scripts/_deploy_api_js_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

73 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy frontend api.js 502 hint + verify shorts on dy.nomadro.live (no API restart)."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "108.174.50.68"
ROOT = Path(__file__).resolve().parents[1]
APP = "/opt/douyinWEB"
REMOTE = r"""#!/usr/bin/env bash
set -euo pipefail
echo "=== api health ==="
systemctl is-active douyinweb-api
curl -sS -o /dev/null -w "health=%{http_code}\n" http://127.0.0.1:8014/api/health
echo "=== channels in db ==="
cd /opt/douyinWEB/backend
.venv/bin/python - <<'PY'
from app import db
rows = db.list_shorts_channels(enabled=None)
print("total", len(rows))
for r in rows:
print(r.get("oauth_profile_id"), "|", r.get("name"), "| yt", (r.get("youtube_channel_id") or "")[:12])
PY
echo "=== build web (api.js only change) ==="
cd /opt/douyinWEB/frontend
npm run build 2>&1 | tail -12
systemctl restart douyinweb-web
sleep 4
systemctl is-active douyinweb-web
curl -sS -o /dev/null -w "web=%{http_code}\n" -k https://127.0.0.1/shorts -H "Host: dy.nomadro.live"
echo DONE
"""
def main() -> None:
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()
local = ROOT / "frontend/src/lib/api.js"
remote = f"{APP}/frontend/src/lib/api.js"
print(f"upload {local.name}")
sftp.put(str(local), remote)
sftp.close()
sftp2 = c.open_sftp()
with sftp2.file("/tmp/deploy_api_js.sh", "w") as f:
f.write(REMOTE)
sftp2.chmod("/tmp/deploy_api_js.sh", 0o755)
sftp2.close()
_i, o, e = c.exec_command("bash /tmp/deploy_api_js.sh", timeout=600)
out = o.read().decode("utf-8", "replace")
err = e.read().decode("utf-8", "replace")
print(out)
if err.strip():
print("STDERR:", err[-2000:])
c.close()
if __name__ == "__main__":
main()