"""Deploy channel/account enable switches (direct SFTP when git push unavailable).""" import paramiko import time HOST = "107.173.30.245" USER = "root" PASSWORD = "Xiao4669805" REPO = "/opt/douyinWEB" LOCAL = "C:/Users/admin/Desktop/douyinWEB" FILES = [ "backend/app/db.py", "backend/app/main.py", "backend/app/tiktok_db.py", "backend/app/x2_db.py", "backend/app/x_clips_db.py", "backend/app/x_clips_pipeline.py", "backend/app/yt_long_db.py", "frontend/src/app/shorts/page.tsx", "frontend/src/app/tiktok/page.tsx", "frontend/src/app/x/page.tsx", "frontend/src/app/yt-long/page.tsx", ] def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() for rel in FILES: remote = f"{REPO}/{rel}" local = f"{LOCAL}/{rel}" print(f"upload {rel}") sftp.put(local, remote) sftp.close() print("[restart api]") c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1", timeout=5) time.sleep(8) _, out, _ = c.exec_command("systemctl is-active douyinweb-api", timeout=15) print("api:", out.read().decode().strip()) print("[npm build]") _, out, _ = c.exec_command(f"cd {REPO}/frontend && npm run build 2>&1 | tail -8", timeout=360) print(out.read().decode("utf-8", "replace").encode("ascii", "replace").decode()) print("[restart web]") c.exec_command("systemctl restart douyinweb-web >/dev/null 2>&1", timeout=5) time.sleep(5) _, out, _ = c.exec_command("systemctl is-active douyinweb-web", timeout=15) print("web:", out.read().decode().strip()) c.close() print("DONE") if __name__ == "__main__": main()