取消本地上传拦截,按 A/B/C/D Client 独立展示配额;新增 SOCKS5 上传代理与删频道级联清理;同步文档与部署脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
103 lines
3.4 KiB
Python
103 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy Shorts SOCKS5 upload proxy support."""
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
REMOTE = "/opt/douyinWEB"
|
|
LOCAL = Path(__file__).resolve().parents[1]
|
|
FILES = [
|
|
"backend/app/shorts_socks.py",
|
|
"backend/app/shorts_upload.py",
|
|
"backend/app/shorts_pipeline.py",
|
|
"backend/app/db.py",
|
|
"backend/app/models.py",
|
|
"backend/app/main.py",
|
|
"backend/requirements.txt",
|
|
"frontend/src/app/settings/page.tsx",
|
|
]
|
|
|
|
|
|
def run(c, cmd, timeout=600):
|
|
print("$", cmd[:200], flush=True)
|
|
chan = c.get_transport().open_session()
|
|
chan.settimeout(timeout)
|
|
chan.get_pty()
|
|
chan.exec_command(cmd)
|
|
buf = []
|
|
while True:
|
|
if chan.recv_ready():
|
|
buf.append(chan.recv(65535).decode("utf-8", "replace"))
|
|
if chan.exit_status_ready() and not chan.recv_ready():
|
|
break
|
|
time.sleep(0.25)
|
|
while chan.recv_ready():
|
|
buf.append(chan.recv(65535).decode("utf-8", "replace"))
|
|
code = chan.recv_exit_status()
|
|
text = "".join(buf)
|
|
clean = "".join(ch for ch in text if ord(ch) < 128 or "\u4e00" <= ch <= "\u9fff")
|
|
print(clean[-2500:], flush=True)
|
|
return code
|
|
|
|
|
|
def main():
|
|
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:
|
|
print("upload", rel, flush=True)
|
|
sftp.put(str(LOCAL / rel), f"{REMOTE}/{rel}")
|
|
sftp.close()
|
|
|
|
run(
|
|
c,
|
|
"cd /opt/douyinWEB/backend && .venv/bin/pip install -q 'httpx[socks]==0.28.1' socksio==1.0.0",
|
|
timeout=180,
|
|
)
|
|
run(
|
|
c,
|
|
"systemctl restart douyinweb-api; sleep 5; systemctl is-active douyinweb-api",
|
|
)
|
|
run(
|
|
c,
|
|
"cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'\n"
|
|
"from app import db\n"
|
|
"from app.shorts_socks import DEFAULT_SOCKS_PROFILES, DEFAULT_SOCKS_PROFILE_ID, resolve_upload_socks_proxy\n"
|
|
"db.init_db()\n"
|
|
"cfg = db.get_settings_map()\n"
|
|
"patch = {}\n"
|
|
"if 'shorts_upload_socks_enabled' not in cfg:\n"
|
|
" patch['shorts_upload_socks_enabled'] = False\n"
|
|
"if not cfg.get('shorts_upload_socks_profile_id'):\n"
|
|
" patch['shorts_upload_socks_profile_id'] = DEFAULT_SOCKS_PROFILE_ID\n"
|
|
"profiles = cfg.get('shorts_upload_socks_profiles')\n"
|
|
"if not isinstance(profiles, list) or not profiles:\n"
|
|
" patch['shorts_upload_socks_profiles'] = DEFAULT_SOCKS_PROFILES\n"
|
|
"if patch:\n"
|
|
" db.update_settings_map(patch)\n"
|
|
"cfg = db.get_settings_map()\n"
|
|
"print('enabled', bool(cfg.get('shorts_upload_socks_enabled')))\n"
|
|
"print('profile_id', cfg.get('shorts_upload_socks_profile_id'))\n"
|
|
"print('profiles', len(cfg.get('shorts_upload_socks_profiles') or []))\n"
|
|
"print('proxy_when_off', repr(resolve_upload_socks_proxy(cfg)))\n"
|
|
"PY",
|
|
timeout=60,
|
|
)
|
|
if run(c, "cd /opt/douyinWEB/frontend && npm run build", timeout=600) != 0:
|
|
raise SystemExit(1)
|
|
run(c, "systemctl restart douyinweb-web; sleep 3; systemctl is-active douyinweb-api douyinweb-web")
|
|
c.close()
|
|
print("DONE")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|