douyinWEB/scripts/_fix_quota_ui_copy_both.py
eric c042320ef1 Clarify Shorts/yt-long quota UI: enabled channels only.
Document fleet-cap rule and drop hardcoded「未达 9 条」copy on Shorts ops cards.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 21:58:53 -05:00

91 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
"""Redeploy Shorts + yt-long UI quota copy fixes to both VPS."""
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]
PASS = "Xiao4669805"
JUMP = "107.173.30.245"
DY = "108.174.50.68"
SH = r'''
set -e
install -D -m 644 /tmp/_q2_shorts.tsx /opt/douyinWEB/frontend/src/app/shorts/page.tsx
install -D -m 644 /tmp/_q2_ytlong.tsx /opt/douyinWEB/frontend/src/app/yt-long/page.tsx
cd /opt/douyinWEB/frontend && npm run build 2>&1 | tail -12
systemctl restart douyinweb-web
sleep 2
systemctl is-active douyinweb-web
# verify enabled-only caps via API status fields
cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'
from app import db, yt_long_db
from app.timeutil import push_date_from_ts
import time
day = push_date_from_ts(time.time())
se = [c for c in (db.list_shorts_channels(enabled=True) or []) if c.get("enabled")]
print("shorts_en", len(se), "cap", sum(int(c.get("daily_max") or 9) for c in se), "gap", db.shorts_total_quota_gap(day))
print("yt_long_cap", yt_long_db.yt_long_enabled_upload_cap(), "src", yt_long_db.yt_long_source_daily_max(), "gap", yt_long_db.yt_long_source_gap(day))
PY
echo HOST_DONE
'''
def wait(c, path, rounds=100):
out = ""
for i in range(rounds):
time.sleep(3)
_, o, _ = c.exec_command(f"tail -c 16000 {path} 2>/dev/null", timeout=15)
out = o.read().decode("utf-8", "replace")
if "HOST_DONE" in out and "EXIT:" in out:
return out
if i % 5 == 0:
print("poll", i, out[-120:].replace("\n", " | "), flush=True)
return out
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(JUMP, 22, "root", PASS, timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for local, remote in (
("frontend/src/app/shorts/page.tsx", "/tmp/_q2_shorts.tsx"),
("frontend/src/app/yt-long/page.tsx", "/tmp/_q2_ytlong.tsx"),
):
data = (ROOT / local).read_bytes().replace(b"\r\n", b"\n")
with sftp.file(remote, "wb") as f:
f.write(data)
print("staged", local, len(data), flush=True)
with sftp.file("/tmp/_q2.sh", "w") as f:
f.write(SH)
sftp.close()
print("===== dylive =====", flush=True)
c.exec_command(
"bash /tmp/_q2.sh > /tmp/_q2_dylive.out 2>&1; echo EXIT:$? >> /tmp/_q2_dylive.out",
timeout=1,
)
print(wait(c, "/tmp/_q2_dylive.out")[-8000:], flush=True)
print("===== dy =====", flush=True)
c.exec_command(
f"SSHPASS={PASS} sshpass -e scp -o StrictHostKeyChecking=no "
f"/tmp/_q2_shorts.tsx /tmp/_q2_ytlong.tsx /tmp/_q2.sh root@{DY}:/tmp/ && "
f"SSHPASS={PASS} sshpass -e ssh -o StrictHostKeyChecking=no root@{DY} "
f"'bash /tmp/_q2.sh' > /tmp/_q2_dy.out 2>&1; echo EXIT:$? >> /tmp/_q2_dy.out",
timeout=1,
)
print(wait(c, "/tmp/_q2_dy.out")[-8000:], flush=True)
c.close()
return 0
if __name__ == "__main__":
raise SystemExit(main())