nomadro/deploy/observability/_deploy_join_group_frontend.py
eric 534400f554 Merge stash WIP onto BMI A/B: join-group, live config, channel tracking.
Keep Douyin homeVariant BMI router intact while restoring admin join-group controls, TLS-safe config fetch, and ntfy channel labels.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-03 15:42:09 +08:00

172 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""Hotfix join-group frontend logic on 82.157.112.245 (source sync + portal rebuild)."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
REPO = Path(__file__).resolve().parents[2]
FILES = [
(
REPO / "src/components/social-follow.tsx",
"/var/www/nomadro.cn/src/components/social-follow.tsx",
),
(
REPO / "apps/miniprogram/h5/src/components/WechatOaModal.tsx",
"/var/www/nomadro.cn/apps/miniprogram/h5/src/components/WechatOaModal.tsx",
),
(
REPO / "apps/miniprogram/h5/src/data/remoteConfig.defaults.ts",
"/var/www/nomadro.cn/apps/miniprogram/h5/src/data/remoteConfig.defaults.ts",
),
(
REPO / "apps/miniprogram/tt/src/components/WechatOaModal.tsx",
"/var/www/nomadro.cn/apps/miniprogram/tt/src/components/WechatOaModal.tsx",
),
(
REPO / "apps/miniprogram/tt/src/data/remoteConfig.defaults.ts",
"/var/www/nomadro.cn/apps/miniprogram/tt/src/data/remoteConfig.defaults.ts",
),
(
REPO / "src/lib/remote-config.ts",
"/var/www/nomadro.cn/src/lib/remote-config.ts",
),
(
REPO / "data/remote-config.json",
"/var/www/nomadro.cn/data/remote-config.json.seed-check",
),
]
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 900) -> int:
print(f"$ {cmd[:200]}", flush=True)
_, stdout, _ = c.exec_command(cmd, timeout=timeout, get_pty=True)
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
time.sleep(0.05)
while stdout.channel.recv_ready():
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
code = stdout.channel.recv_exit_status()
print(f"[exit {code}]", flush=True)
return code
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
HOST,
username=USER,
password=PASS,
timeout=60,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
t = c.get_transport()
if t:
t.set_keepalive(15)
sftp = c.open_sftp()
for local, remote in FILES:
if not local.is_file():
print("missing", local)
return 1
# seed-check: don't overwrite live remote-config; only upload sources
if remote.endswith(".seed-check"):
print("skip live remote-config overwrite:", remote)
continue
print(f"upload {local.name} -> {remote}", flush=True)
# ensure parent exists & writable via temp then sudo mv
tmp = f"/tmp/jgfix_{local.name}"
with sftp.file(tmp, "wb") as rf:
rf.write(local.read_bytes())
run(c, f"sudo cp {tmp} {remote} && sudo chown ubuntu:ubuntu {remote} && rm -f {tmp}", 60)
sftp.close()
# Additive flags only (never wipe)
run(
c,
r"""
sudo python3 <<'PY'
import json
from pathlib import Path
p = Path('/var/www/nomadro.cn/data/remote-config.json')
cfg = json.loads(p.read_text(encoding='utf-8'))
flags = cfg.setdefault('flags', {})
copy = cfg.setdefault('copy', {})
changed = False
for k, v in {
'joinGroupWechat': True,
'joinGroupDouyin': False,
'socialFollowAuto': False,
}.items():
if k not in flags:
flags[k] = v
changed = True
for k, v in {
'wechatOaName': '异度世界',
'joinGroupDouyinHint': '打开抖音搜群「数字游民」或扫码进群',
'joinGroupDouyinQr': '',
}.items():
if k not in copy:
copy[k] = v
changed = True
if changed:
p.write_text(json.dumps(cfg, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
print('seeded flags')
else:
print('flags ok')
print('flags', {k: flags.get(k) for k in ('joinGroupWechat','joinGroupDouyin','socialFollowAuto','socialFollow')})
PY
""",
60,
)
# Verify TT modal no longer switches on later
run(
c,
r"""
grep -n 'onLater\|setShowOa\|joinGroupWechat\|稍后再说' \
/var/www/nomadro.cn/apps/miniprogram/tt/src/components/WechatOaModal.tsx \
/var/www/nomadro.cn/src/components/social-follow.tsx | head -40
""",
30,
)
# Rebuild portal (source-based production)
code = run(
c,
r"""
set -euo pipefail
cd /var/www/nomadro.cn
# preserve remote-config across build side effects
cp -a data/remote-config.json /tmp/remote-config.pre-jg.json
export NODE_OPTIONS=--max-old-space-size=4096
/usr/local/bin/pnpm build
cp -a /tmp/remote-config.pre-jg.json data/remote-config.json
sudo systemctl restart nomadro.service
sleep 4
systemctl is-active nomadro.service
curl -sk -o /dev/null -w 'portal %{http_code}\n' https://nomadro.cn/
curl -sk https://nomadro.cn/api/config | python3 -c "import sys,json; f=json.load(sys.stdin).get('config',{}).get('flags',{}); print('flags', {k:f.get(k) for k in ('joinGroupWechat','joinGroupDouyin','socialFollowAuto')})"
grep -n 'joinGroupWechat\|稍后再说\|DISMISS_KEY\|setShowOa' src/components/social-follow.tsx | head -20
echo DONE
""",
1200,
)
c.close()
return code
if __name__ == "__main__":
raise SystemExit(main())