# -*- coding: utf-8 -*- """Hotfix neko gateway trailing-slash redirect; verify /neko/5 → /neko/5/.""" from __future__ import annotations import sys from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") LOCAL = Path(__file__).resolve().parents[1] / "backend/app/neko_edge_gateway.py" REMOTE = "/opt/douyinWEB/backend/app/neko_edge_gateway.py" PASS = "4669805" def main(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 4014, "eric", PASS, timeout=45, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/neko_edge_gateway.py", "w") as f: f.write(LOCAL.read_text(encoding="utf-8")) sftp.close() _, o, e = c.exec_command( f"echo '{PASS}' | sudo -S -p '' bash -lc '" f"install -m 644 /tmp/neko_edge_gateway.py {REMOTE}; " "systemctl restart douyinweb-api; sleep 4; " "systemctl is-active douyinweb-api; " "curl -sS -m 5 -o /dev/null -w \"bare=%{http_code} loc=%{{redirect_url}}\\n\" " "-D - http://127.0.0.1:9199/neko/5 -o /dev/null | head -20; " "curl -sS -m 5 -o /dev/null -w \"slash=%{http_code}\\n\" http://127.0.0.1:9199/neko/5/; " "curl -sS -m 8 -o /dev/null -w \"pub_bare=%{http_code} url=%{url_effective}\\n\" " "-L https://dy.nomadro.com/neko/5; " "curl -sS -m 8 -o /dev/null -w \"pub_js=%{http_code}\\n\" " "https://dy.nomadro.com/neko/5/js/app.5d9731bf.js" "'", timeout=90, ) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() if __name__ == "__main__": main()