# -*- coding: utf-8 -*- """Deploy Shorts progress = uploaded-only (UI + board + fill min_met).""" from __future__ import annotations import json import sys import time import http.cookiejar import urllib.request from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB") FILES = [ "backend/app/db.py", "backend/app/shorts_schedule.py", "backend/app/shorts_pipeline.py", "frontend/src/app/shorts/page.tsx", ] REMOTE = r"""#!/bin/bash set -euo pipefail ROOT=/opt/douyinWEB # drop stale markers from older deploys for j in $(seq 0 15); do [ -f "/tmp/_dy_spu_${j}.path" ] || continue done i=0 while [ -f "/tmp/_dy_spu_${i}.path" ]; do rel=$(cat "/tmp/_dy_spu_${i}.path") dst="$ROOT/$rel" mkdir -p "$(dirname "$dst")" python3 -c "from pathlib import Path; p=Path('/tmp/_dy_spu_${i}.bin'); d=Path('$dst'); d.write_bytes(p.read_bytes().replace(b'\r\n',b'\n').replace(b'\r',b'\n')); print('ok', d)" i=$((i+1)) done systemctl restart douyinweb-api.service sleep 5 systemctl is-active douyinweb-api.service cd "$ROOT/backend" PYBIN=$(systemctl show -p ExecStart --value douyinweb-api.service | awk '{print $1}') if [ -x "$PYBIN" ]; then PYTHONPATH=. "$PYBIN" - <<'PY' || true from app.shorts_schedule import pull_forward_due_uploads print("pull_forward", pull_forward_due_uploads()) PY else echo "skip pull_forward, no PYBIN" fi cd "$ROOT/frontend" npm run build >/tmp/dy_spu_fe.log 2>&1 && echo FE_OK || { echo FE_FAIL; tail -40 /tmp/dy_spu_fe.log; exit 1; } systemctl restart douyinweb-web.service sleep 3 systemctl is-active douyinweb-web.service grep -nE 'pull_forward_due_uploads|EMERGENCY_CHANNEL_GAP' \ "$ROOT/backend/app/shorts_schedule.py" | head -15 curl -sS -m 5 http://127.0.0.1:8014/api/ping; echo """ def deploy(label, host, port, user, pw, *, sudo): print(f"\n===== {label} =====") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(host, port, user, pw, timeout=45, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() for i, rel in enumerate(FILES): data = (ROOT / rel).read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n") with sftp.file(f"/tmp/_dy_spu_{i}.bin", "wb") as f: f.write(data) with sftp.file(f"/tmp/_dy_spu_{i}.path", "w") as f: f.write(rel.replace("\\", "/")) # clear leftover path markers for j in range(len(FILES), 12): try: sftp.remove(f"/tmp/_dy_spu_{j}.path") except Exception: pass with sftp.file("/tmp/_dy_spu_remote.sh", "w") as f: f.write(REMOTE.replace("\r\n", "\n")) sftp.close() cmd = f"echo '{pw}' | sudo -S -p '' bash /tmp/_dy_spu_remote.sh" if sudo else "bash /tmp/_dy_spu_remote.sh" _, o, e = c.exec_command(cmd, timeout=600) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() def pub(base): cj = http.cookiejar.CookieJar() op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) data = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode() req = urllib.request.Request( base + "/api/auth/login", data=data, method="POST", headers={"Content-Type": "application/json"} ) try: op.open(req, timeout=30) with op.open(urllib.request.Request(base + "/api/shorts/schedule"), timeout=40) as r: board = json.loads(r.read().decode()) chans = board.get("channels") or [] sample = [] for c in chans[:8]: if not c.get("enabled"): continue sample.append( { "name": c.get("name"), "used": c.get("used"), "uploaded": c.get("uploaded"), "pending": c.get("pending"), "scheduled": c.get("scheduled"), "gap": c.get("gap"), "max_met": c.get("max_met"), } ) print(base, "day=", board.get("push_date"), "sample=", json.dumps(sample, ensure_ascii=False)) except Exception as exc: print(base, "ERR", exc) deploy("vps", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False) deploy("phys", "107.173.30.245", 4014, "eric", "4669805", sudo=True) time.sleep(4) print("\n===== public =====") for b in ("https://dy.nomadro.com", "https://dylive.nomadro.com"): pub(b) print("done")