# -*- coding: utf-8 -*- """Deploy cover fix + enable S3 public read on dy.nomadro.live.""" 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" FILES = [ "backend/app/main.py", "backend/app/db.py", ] REMOTE = r"""#!/usr/bin/env bash set -euo pipefail echo "=== anonymous read on douyin-covers ===" printf 's3.bucket.access -name douyin-covers -user anonymous -access Read,List\nexit\n' \ | /opt/seaweedfs/weed shell -master=127.0.0.1:9333 2>&1 | tail -15 || true KEY=$(cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY' from app import db for s in db.list_active_sessions(): cp = str(s.get('cover_path') or '') if '/douyin-covers/' in cp: print(cp.split('/douyin-covers/', 1)[-1]) break PY ) echo "sample_key=$KEY" if [ -n "$KEY" ]; then curl -sS -o /dev/null -w "anon=%{http_code} sz=%{size_download}\n" \ "http://127.0.0.1:8333/douyin-covers/$KEY" curl -sS -o /dev/null -w "nginx=%{http_code} sz=%{size_download}\n" -k \ "https://127.0.0.1/douyin-covers/$KEY" -H "Host: dy.nomadro.live" fi echo "=== restart api ===" systemctl restart douyinweb-api sleep 5 systemctl is-active douyinweb-api curl -sS -o /dev/null -w "health=%{http_code}\n" http://127.0.0.1:8014/api/health 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() for rel in FILES: print("upload", rel) sftp.put(str(ROOT / rel), f"{APP}/{rel.replace(chr(92), '/')}") with sftp.file("/tmp/deploy_cover_fix.sh", "w") as f: f.write(REMOTE) sftp.chmod("/tmp/deploy_cover_fix.sh", 0o755) sftp.close() _i, o, e = c.exec_command("bash /tmp/deploy_cover_fix.sh", timeout=180) print(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace").strip() if err: print("ERR", err[-2000:]) c.close() if __name__ == "__main__": main()