douyinWEB/scripts/_publish_x_limit_ext.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

70 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
"""Upload built extension dist + publish zip to S3 downloads."""
from __future__ import annotations
import os, sys, paramiko
from pathlib import Path
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
LOCAL = Path(r"c:\Users\admin\Desktop\douyinWEB\extensions\dylive-helper")
REMOTE = "/opt/douyinWEB/extensions/dylive-helper"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
def ensure_dir(remote: str) -> None:
parts = remote.strip("/").split("/")
cur = ""
for p in parts:
cur += "/" + p
try:
sftp.stat(cur)
except FileNotFoundError:
sftp.mkdir(cur)
def upload_tree(local: Path, remote: str) -> int:
n = 0
ensure_dir(remote)
for root, dirs, files in os.walk(local):
rel = os.path.relpath(root, local).replace("\\", "/")
rdir = remote if rel == "." else f"{remote}/{rel}"
ensure_dir(rdir)
for f in files:
lp = Path(root) / f
rp = f"{rdir}/{f}"
sftp.put(str(lp), rp)
n += 1
return n
# sync source content.ts + manifest + built dist
for name in ("manifest.json", "package.json", "src/content.ts"):
lp = LOCAL / name
rp = f"{REMOTE}/{name.replace(chr(92), '/')}"
ensure_dir(str(Path(rp).parent).replace("\\", "/"))
sftp.put(str(lp), rp)
print("put", name)
n = upload_tree(LOCAL / "dist", f"{REMOTE}/dist")
print("dist files", n)
sftp.close()
def run(cmd, timeout=420):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace").strip()
print(run("grep -o 'X_DAILY_POST_LIMIT' /opt/douyinWEB/extensions/dylive-helper/dist/content.js | head -n 3"))
print(run("python3 -c \"import json; print(json.load(open('/opt/douyinWEB/extensions/dylive-helper/dist/manifest.json')).get('version'))\""))
pub = r"""
export DY_S3_ENABLED=true
export DY_S3_ENDPOINT=http://127.0.0.1:8333
export DY_S3_PUBLIC_BASE=https://s3.nomadro.com
export DY_S3_ACCESS_KEY=douyin
export DY_S3_SECRET_KEY=douyinweb_s3_2026
export DY_S3_BUCKET=douyin-covers
export DY_S3_REGION=us-east-1
cd /opt/douyinWEB/backend
/opt/douyinWEB/backend/.venv/bin/python /opt/douyinWEB/scripts/_publish_downloads.py --ext-only
"""
print(run(pub + " 2>&1 | tail -n 40", timeout=420))
c.close()
print("DONE")