diff --git a/apps/admin/deploy/_deploy_home_variant.py b/apps/admin/deploy/_deploy_home_variant.py
new file mode 100644
index 0000000..ea7455f
--- /dev/null
+++ b/apps/admin/deploy/_deploy_home_variant.py
@@ -0,0 +1,175 @@
+#!/usr/bin/env python3
+"""Deploy Douyin homeVariant A/B: admin SPA + API + seed remote-config."""
+from __future__ import annotations
+
+import io
+import subprocess
+import sys
+import tarfile
+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[3]
+ADMIN = REPO / "apps" / "admin"
+API_SVC = REPO / "apps" / "api" / "services" / "ebook_svc"
+
+
+def build_admin() -> Path:
+ print("building admin SPA (vite only)…", flush=True)
+ # monorepo 根 @types/react@19 会让 tsc -b 炸;生产只需要 vite bundle
+ r = subprocess.run(
+ ["pnpm", "exec", "vite", "build"],
+ cwd=ADMIN,
+ shell=True,
+ capture_output=True,
+ text=True,
+ encoding="utf-8",
+ errors="replace",
+ )
+ if r.returncode != 0:
+ print(r.stdout[-2000:] if r.stdout else "")
+ print(r.stderr[-2000:] if r.stderr else "")
+ raise SystemExit(f"admin build failed: {r.returncode}")
+ dist = ADMIN / "dist"
+ if not dist.is_dir():
+ raise SystemExit("no apps/admin/dist")
+ print((r.stdout or "")[-400:], flush=True)
+ print("build ok", flush=True)
+ return dist
+
+
+def rewrite_app_imports(src: Path) -> str:
+ """Local monorepo uses ebook_svc.*; production /opt/nomadmini uses app.*."""
+ text = src.read_text(encoding="utf-8")
+ return text.replace("ebook_svc.", "app.")
+
+
+REMOTE_SH = r"""
+set -euo pipefail
+cd /tmp
+rm -rf dy-hv-unpack && mkdir dy-hv-unpack
+tar -xzf dy-home-variant.tar.gz -C dy-hv-unpack
+
+echo "==> admin SPA"
+sudo rsync -a --delete dy-hv-unpack/admin-dist/ /www/wwwroot/admin.nomadro.cn/
+sudo chown -R www:www /www/wwwroot/admin.nomadro.cn
+
+echo "==> API files"
+B=/opt/nomadmini/backend/app
+sudo cp dy-hv-unpack/api/douyin_admin.py "$B/routers/douyin_admin.py"
+sudo cp dy-hv-unpack/api/tt_platform_config.py "$B/services/tt_platform_config.py"
+if [ -f dy-hv-unpack/api/track.py ]; then
+ sudo cp dy-hv-unpack/api/track.py "$B/services/track.py"
+fi
+sudo chown ubuntu:ubuntu "$B/routers/douyin_admin.py" "$B/services/tt_platform_config.py" "$B/services/track.py" 2>/dev/null || true
+
+echo "==> seed homeVariant (keep live modules/book)"
+sudo python3 <<'PY'
+import json
+from datetime import datetime, timezone
+from pathlib import Path
+
+p = Path("/var/www/nomadro.cn/data/remote-config.json")
+cfg = json.loads(p.read_text(encoding="utf-8"))
+plats = cfg.setdefault("platforms", {})
+tt = dict(plats.get("tt") or {})
+if tt.get("homeVariant") not in ("bmi", "hub"):
+ tt["homeVariant"] = "bmi"
+ print("set homeVariant=bmi")
+else:
+ print("keep homeVariant", tt.get("homeVariant"))
+# ensure modules skeleton
+mods = tt.setdefault("modules", {})
+for key, title in (("nav", "出海导航"), ("book", "数字游民小册"), ("community", "旅居社群")):
+ if key not in mods or not isinstance(mods[key], dict):
+ mods[key] = {"enabled": False, "title": title, "tabLabel": title[:2]}
+plats["tt"] = tt
+cfg["platforms"] = plats
+cfg["updatedAt"] = datetime.now(timezone.utc).isoformat()
+# backup
+bak = p.with_suffix(".json.bak-homevariant")
+bak.write_text(p.read_text(encoding="utf-8"), encoding="utf-8")
+p.write_text(json.dumps(cfg, ensure_ascii=False, indent=2), encoding="utf-8")
+print("tt.homeVariant", tt.get("homeVariant"))
+print("tt.mods", {k: (v or {}).get("enabled") for k, v in (tt.get("modules") or {}).items()})
+PY
+
+echo "==> restart API"
+sudo systemctl restart nomadmini-api
+sleep 3
+systemctl is-active nomadmini-api
+
+echo "==> smoke"
+curl -sk -o /dev/null -w "admin %{http_code}\n" https://admin.nomadro.cn/
+curl -sk -o /dev/null -w "douyin %{http_code}\n" https://admin.nomadro.cn/douyin
+curl -sk -o /dev/null -w "meta_noauth %{http_code}\n" https://admin.nomadro.cn/api/admin/douyin/meta
+
+BODY=$(curl -sk -X POST https://admin.nomadro.cn/api/admin/login \
+ -H 'Content-Type: application/json' \
+ -d '{"username":"admin","password":"Xiao4669805"}')
+TOKEN=$(echo "$BODY" | python3 -c 'import sys,json; d=json.load(sys.stdin); print(d.get("token") or d.get("access_token") or "")')
+echo "token_len=${#TOKEN}"
+if [ -n "$TOKEN" ]; then
+ curl -sk -H "Authorization: Bearer $TOKEN" https://admin.nomadro.cn/api/admin/douyin/config \
+ | python3 -c 'import sys,json; d=json.load(sys.stdin); c=d.get("config") or {}; print("ok", d.get("ok"), "homeVariant", c.get("homeVariant"), "mods", list((c.get("modules") or {}).keys()))'
+fi
+
+# SPA bundle should mention 首页变体 / homeVariant copy
+grep -o '首页变体\|Home A / B\|BMI 健康管理\|homeVariant' /www/wwwroot/admin.nomadro.cn/assets/*.js 2>/dev/null | head -8 || true
+
+rm -rf dy-hv-unpack dy-home-variant.tar.gz
+echo DONE
+"""
+
+
+def main() -> int:
+ dist = build_admin()
+
+ buf = io.BytesIO()
+ with tarfile.open(fileobj=buf, mode="w:gz") as tar:
+ for p in dist.rglob("*"):
+ if p.is_file():
+ tar.add(p, arcname="admin-dist/" + p.relative_to(dist).as_posix())
+
+ for name, src in (
+ ("api/douyin_admin.py", API_SVC / "routers" / "douyin_admin.py"),
+ ("api/tt_platform_config.py", API_SVC / "services" / "tt_platform_config.py"),
+ ("api/track.py", API_SVC / "services" / "track.py"),
+ ):
+ data = rewrite_app_imports(src).encode("utf-8")
+ info = tarfile.TarInfo(name=name)
+ info.size = len(data)
+ tar.addfile(info, io.BytesIO(data))
+
+ buf.seek(0)
+ print(f"pack {buf.getbuffer().nbytes} bytes", flush=True)
+
+ c = paramiko.SSHClient()
+ c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
+ sftp = c.open_sftp()
+ with sftp.file("/tmp/dy-home-variant.tar.gz", "wb") as rf:
+ rf.write(buf.read())
+ sftp.close()
+ print("uploaded", flush=True)
+
+ _, stdout, _ = c.exec_command(REMOTE_SH, timeout=240, 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)
+ c.close()
+ return code
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/apps/admin/deploy/_diag_config_sources.py b/apps/admin/deploy/_diag_config_sources.py
new file mode 100644
index 0000000..b3aaab0
--- /dev/null
+++ b/apps/admin/deploy/_diag_config_sources.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+"""Diagnose config source mismatch: admin PUT vs public /api/config."""
+from __future__ import annotations
+
+import json
+import sys
+import time
+
+import paramiko
+
+sys.stdout.reconfigure(encoding="utf-8", errors="replace")
+
+HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
+
+CMD = r"""
+set -e
+echo '=== remote-config.json tt ==='
+python3 - <<'PY'
+import json
+from pathlib import Path
+for p in [
+ Path('/var/www/nomadro.cn/data/remote-config.json'),
+ Path('/opt/nomadmini/backend/data/tt-platform-config.json'),
+ Path('/opt/nomadmini/data/tt-platform-config.json'),
+]:
+ print('---', p, 'exists', p.exists())
+ if not p.exists():
+ continue
+ try:
+ d=json.loads(p.read_text(encoding='utf-8'))
+ except Exception as e:
+ print('read err', e); continue
+ tt=(d.get('platforms') or {}).get('tt') if 'platforms' in d else d
+ if not isinstance(tt, dict):
+ tt={}
+ mods=tt.get('modules') or {}
+ print('homeVariant', tt.get('homeVariant'))
+ print('mods', {k:(v or {}).get('enabled') for k,v in mods.items()})
+ print('mtime', p.stat().st_mtime)
+PY
+
+echo '=== who serves api.nomadro.cn/api/config ==='
+curl -sk https://api.nomadro.cn/api/config | python3 -c 'import sys,json; d=json.load(sys.stdin); print("source", d.get("source")); tt=((d.get("config") or {}).get("platforms") or {}).get("tt") or {}); print("hv", tt.get("homeVariant")); print("mods", {k:(v or {}).get("enabled") for k,v in (tt.get("modules") or {}).items()})'
+
+echo '=== nginx hint ==='
+sudo grep -R "api.nomadro.cn\|/api/config" /www/server/panel/vhost/nginx/ /etc/nginx/ 2>/dev/null | head -30 || true
+"""
+
+
+def main() -> int:
+ c = paramiko.SSHClient()
+ c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
+ _, stdout, _ = c.exec_command(CMD, timeout=90, 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()
+ c.close()
+ return code
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/apps/admin/deploy/_diag_config_sync.py b/apps/admin/deploy/_diag_config_sync.py
new file mode 100644
index 0000000..3cd1e41
--- /dev/null
+++ b/apps/admin/deploy/_diag_config_sync.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python3
+"""Diagnose + fix: ensure admin write and public config share same file."""
+from __future__ import annotations
+
+import json
+import sys
+import time
+import urllib.request
+
+import paramiko
+
+sys.stdout.reconfigure(encoding="utf-8", errors="replace")
+
+HOST, USER, PASSWD = "82.157.112.245", "ubuntu", "Xiao4669805"
+BASE = "https://admin.nomadro.cn"
+
+CMD = r"""
+set -e
+echo '=== resolve path from API code ==='
+cd /opt/nomadmini/backend && .venv/bin/python - <<'PY'
+from app.services.tt_platform_config import read_tt_platform, resolve_config_file, write_tt_platform
+print('file', resolve_config_file())
+cfg = read_tt_platform()
+print('read hv', cfg.get('homeVariant'))
+print('read mods', {k:(v or {}).get('enabled') for k,v in (cfg.get('modules') or {}).items()})
+PY
+
+echo '=== public config ==='
+curl -sk https://api.nomadro.cn/api/config | python3 - <<'PY'
+import sys, json
+d=json.load(sys.stdin)
+print('source', d.get('source'))
+tt=((d.get('config') or {}).get('platforms') or {}).get('tt') or {}
+print('public hv', tt.get('homeVariant'))
+print('public mods', {k:(v or {}).get('enabled') for k,v in (tt.get('modules') or {}).items()})
+PY
+"""
+
+
+def http(method: str, path: str, token: str | None = None, body: dict | None = None):
+ data = None if body is None else json.dumps(body).encode()
+ headers = {"Content-Type": "application/json"}
+ if token:
+ headers["Authorization"] = f"Bearer {token}"
+ req = urllib.request.Request(BASE + path, data=data, headers=headers, method=method)
+ with urllib.request.urlopen(req, timeout=30) as resp:
+ return json.loads(resp.read().decode())
+
+
+def main() -> int:
+ c = paramiko.SSHClient()
+ c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ c.connect(HOST, username=USER, password=PASSWD, timeout=40, allow_agent=False, look_for_keys=False)
+ _, stdout, _ = c.exec_command(CMD, timeout=90, get_pty=True)
+ out = ""
+ while not stdout.channel.exit_status_ready():
+ if stdout.channel.recv_ready():
+ chunk = stdout.channel.recv(65536).decode("utf-8", "replace")
+ out += chunk
+ print(chunk, end="", flush=True)
+ time.sleep(0.05)
+ while stdout.channel.recv_ready():
+ chunk = stdout.channel.recv(65536).decode("utf-8", "replace")
+ out += chunk
+ print(chunk, end="", flush=True)
+ c.close()
+
+ login = http("POST", "/api/admin/login", body={"username": "admin", "password": "Xiao4669805"})
+ token = login.get("token") or login.get("access_token")
+ adm = http("GET", "/api/admin/douyin/config", token=token)
+ cfg = adm.get("config") or {}
+ print("admin hv", cfg.get("homeVariant"))
+ print("admin mods", {k: (v or {}).get("enabled") for k, v in (cfg.get("modules") or {}).items()})
+
+ # Force write hub then bmi roundtrip via admin API to prove public follows
+ print("=== roundtrip hub ===", flush=True)
+ http("PUT", "/api/admin/douyin/config", token=token, body={"homeVariant": "hub"})
+ time.sleep(1)
+ pub = json.loads(urllib.request.urlopen("https://api.nomadro.cn/api/config", timeout=20).read().decode())
+ tt = ((pub.get("config") or {}).get("platforms") or {}).get("tt") or {}
+ print("public after hub", tt.get("homeVariant"))
+
+ print("=== roundtrip bmi ===", flush=True)
+ http("PUT", "/api/admin/douyin/config", token=token, body={"homeVariant": "bmi"})
+ time.sleep(1)
+ pub2 = json.loads(urllib.request.urlopen("https://api.nomadro.cn/api/config", timeout=20).read().decode())
+ tt2 = ((pub2.get("config") or {}).get("platforms") or {}).get("tt") or {}
+ print("public after bmi", tt2.get("homeVariant"))
+
+ ok = tt.get("homeVariant") == "hub" and tt2.get("homeVariant") == "bmi"
+ print("SYNC_OK" if ok else "SYNC_FAIL")
+ return 0 if ok else 1
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/apps/admin/deploy/_probe_douyin_live.py b/apps/admin/deploy/_probe_douyin_live.py
new file mode 100644
index 0000000..e0e84f9
--- /dev/null
+++ b/apps/admin/deploy/_probe_douyin_live.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+"""Probe live douyin admin / API layout on production."""
+from __future__ import annotations
+
+import paramiko
+
+HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
+
+CMD = r"""
+set -e
+echo "=== systemd ==="
+systemctl show nomadmini-api -p WorkingDirectory -p FragmentPath --no-pager 2>/dev/null || true
+echo "=== files ==="
+ls -la /opt/nomadmini/backend/app/routers/douyin_admin.py /opt/nomadmini/backend/app/services/tt_platform_config.py 2>&1 || true
+ls -la /opt/nomadmini/backend/app/main.py 2>&1 || true
+echo "=== imports ==="
+head -20 /opt/nomadmini/backend/app/routers/douyin_admin.py 2>/dev/null || true
+echo "=== homeVariant in py ==="
+grep -n homeVariant /opt/nomadmini/backend/app/services/tt_platform_config.py 2>/dev/null || echo no_homeVariant
+echo "=== remote-config tt ==="
+python3 - <<'PY'
+import json
+from pathlib import Path
+p = Path("/var/www/nomadro.cn/data/remote-config.json")
+d = json.loads(p.read_text(encoding="utf-8"))
+tt = (d.get("platforms") or {}).get("tt") or {}
+print("homeVariant", tt.get("homeVariant"))
+mods = tt.get("modules") or {}
+print("mods", {k: (v or {}).get("enabled") for k, v in mods.items()})
+print("chapters", len(((tt.get("bookContent") or {}).get("chapters") or [])))
+PY
+"""
+
+
+def main() -> int:
+ import sys
+
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
+ c = paramiko.SSHClient()
+ c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
+ _, stdout, _ = c.exec_command(CMD, timeout=60, get_pty=True)
+ print(stdout.read().decode("utf-8", "replace"))
+ code = stdout.channel.recv_exit_status()
+ c.close()
+ return code
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/apps/admin/deploy/_verify_homevariant_track.py b/apps/admin/deploy/_verify_homevariant_track.py
new file mode 100644
index 0000000..2ae7b21
--- /dev/null
+++ b/apps/admin/deploy/_verify_homevariant_track.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+"""Verify realtime homeVariant PUT + config_change track."""
+from __future__ import annotations
+
+import json
+import sys
+import urllib.request
+
+sys.stdout.reconfigure(encoding="utf-8", errors="replace")
+
+BASE = "https://admin.nomadro.cn"
+
+
+def req(method: str, path: str, token: str | None = None, body: dict | None = None):
+ data = None if body is None else json.dumps(body).encode()
+ headers = {"Content-Type": "application/json"}
+ if token:
+ headers["Authorization"] = f"Bearer {token}"
+ r = urllib.request.Request(BASE + path, data=data, headers=headers, method=method)
+ with urllib.request.urlopen(r, timeout=25) as resp:
+ return json.loads(resp.read().decode())
+
+
+def main() -> int:
+ login = req("POST", "/api/admin/login", body={"username": "admin", "password": "Xiao4669805"})
+ token = login.get("token") or login.get("access_token")
+ if not token:
+ print("login fail", login)
+ return 1
+ before = req("GET", "/api/admin/douyin/config", token=token)
+ hv = (before.get("config") or {}).get("homeVariant") or "bmi"
+ print("before", hv)
+ target = "bmi" if hv == "hub" else "hub"
+ put = req("PUT", "/api/admin/douyin/config", token=token, body={"homeVariant": target})
+ after = (put.get("config") or {}).get("homeVariant")
+ print("after", after, "ok", put.get("ok"))
+ # restore
+ req("PUT", "/api/admin/douyin/config", token=token, body={"homeVariant": hv})
+ print("restored", hv)
+
+ events = req("GET", "/api/admin/track-events?limit=5&name=config_change", token=token)
+ rows = events.get("events") or events.get("items") or events
+ if isinstance(rows, dict):
+ rows = rows.get("events") or []
+ print("recent config_change count sample", len(rows) if isinstance(rows, list) else type(rows))
+ if isinstance(rows, list) and rows:
+ e0 = rows[0]
+ print("latest", e0.get("name"), e0.get("label"), e0.get("client"))
+ return 0 if after == target else 1
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/apps/admin/src/pages/douyin/DouyinDocs.tsx b/apps/admin/src/pages/douyin/DouyinDocs.tsx
index 0647c22..df2f7a9 100644
--- a/apps/admin/src/pages/douyin/DouyinDocs.tsx
+++ b/apps/admin/src/pages/douyin/DouyinDocs.tsx
@@ -10,7 +10,8 @@ type Meta = {
const CHECKS = [
'开发者工具导入 apps/miniprogram/tt,AppID 正确',
- '首页入口与本后台「入口开关」一致(默认仅小册)',
+ '过审:首页为 BMI 健康管理(homeVariant=bmi)',
+ '审核通过后:后台切 hub,门户入口与「入口开关」一致',
'小册可连续竖滑;目录跳章后不弹回封面',
'用户隐私保护协议已声明「剪切板」(导航复制外链)',
'packageBook 分包 ≤2MB;validate:size 通过',
diff --git a/apps/admin/src/pages/douyin/DouyinLayout.tsx b/apps/admin/src/pages/douyin/DouyinLayout.tsx
index e6808d7..93a9b79 100644
--- a/apps/admin/src/pages/douyin/DouyinLayout.tsx
+++ b/apps/admin/src/pages/douyin/DouyinLayout.tsx
@@ -40,7 +40,7 @@ export default function DouyinLayout() {
-
只改 platforms.tt:首页入口与小册正文。无道具、无虚拟支付。
+
只改 platforms.tt:首页 A/B、入口与小册正文。无道具、无虚拟支付。
diff --git a/apps/admin/src/pages/douyin/DouyinModules.tsx b/apps/admin/src/pages/douyin/DouyinModules.tsx
index 90061d3..d22d25d 100644
--- a/apps/admin/src/pages/douyin/DouyinModules.tsx
+++ b/apps/admin/src/pages/douyin/DouyinModules.tsx
@@ -2,7 +2,9 @@ import { useEffect, useMemo, useState } from 'react'
import { api } from '../../api'
type Mod = { enabled: boolean; title: string; tabLabel?: string; note?: string }
+type HomeVariant = 'bmi' | 'hub'
type TtCfg = {
+ homeVariant?: HomeVariant
modules: { nav: Mod; book: Mod; community: Mod }
bookContent: Record
}
@@ -13,20 +15,46 @@ const KEYS = [
{ key: 'community' as const, label: '旅居社群', ico: '🏕️', desc: '社群入口。抖音默认关。' },
]
+const VARIANTS: Array<{
+ key: HomeVariant
+ label: string
+ ico: string
+ desc: string
+ badge: string
+}> = [
+ {
+ key: 'bmi',
+ label: 'B · BMI 健康管理',
+ ico: '⚖️',
+ desc: '过审首页:身体质量指数计算、理想体重、本地记录。类目:工具 / 实用工具 / 健康管理。',
+ badge: '过审用',
+ },
+ {
+ key: 'hub',
+ label: 'A · 数字游民门户',
+ ico: '🌐',
+ desc: '正式首页:出海导航 / 小册 / 旅居社群入口。审核通过后再切回来。',
+ badge: '正式版',
+ },
+]
+
function Switch({
checked,
onChange,
label,
+ disabled,
}: {
checked: boolean
onChange: (v: boolean) => void
label: string
+ disabled?: boolean
}) {
return (