Includes social realtime entrypoints, weapp audit book surfaces, VIP analytics track routes, MiroTalk/Centrifugo deploy helpers, and related admin/config wiring. Excludes local DB dumps and .tmp probe scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
183 lines
7.7 KiB
Python
183 lines
7.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Deep zh-CN + nomadro UI for MiroTalk (no Google Translate dependency)."""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import paramiko
|
|
|
|
HOST = "82.157.112.245"
|
|
USER = "ubuntu"
|
|
PASS = "Xiao4669805"
|
|
BASE = "/opt/nomadro-services/mirotalk"
|
|
HERE = Path(__file__).resolve().parent
|
|
|
|
|
|
def ssh():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=30, allow_agent=False, look_for_keys=False)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, timeout=120):
|
|
_i, o, e = c.exec_command(cmd, timeout=timeout)
|
|
out = o.read().decode("utf-8", "ignore")
|
|
err = e.read().decode("utf-8", "ignore")
|
|
return out + (("\n" + err) if err.strip() else ""), o.channel.recv_exit_status()
|
|
|
|
|
|
def write(c, remote: str, data: str):
|
|
tmp = f"/tmp/{Path(remote).name}"
|
|
sftp = c.open_sftp()
|
|
with sftp.file(tmp, "w") as f:
|
|
f.write(data.encode("utf-8"))
|
|
sftp.close()
|
|
out, code = run(c, f"sudo mv {tmp} {remote} && sudo chmod 644 {remote}")
|
|
if code != 0:
|
|
raise RuntimeError(out)
|
|
|
|
|
|
def patch_client_js(text: str) -> str:
|
|
reps = {
|
|
"title: brand.app?.name || 'MiroTalk P2P'": "title: brand.app?.name || 'nomadro'",
|
|
"inputPlaceholder: 'Enter your email or name'": "inputPlaceholder: '输入昵称'",
|
|
"confirmButtonText: `Join meeting`": "confirmButtonText: '进入房间'",
|
|
"if (!value) return 'Please enter your email or name';": "if (!value) return '请输入昵称';",
|
|
"return isEmail ? 'Email must be max 254 char' : 'Name must be max 32 char';":
|
|
"return isEmail ? '邮箱最多 254 个字符' : '昵称最多 32 个字符';",
|
|
"return 'Invalid name!';": "return '昵称无效';",
|
|
"return 'Username is already in use!';": "return '昵称已被占用';",
|
|
"setTippy(initScreenShareBtn, 'Toggle screen sharing', 'top');":
|
|
"setTippy(initScreenShareBtn, '切换屏幕共享', 'top');",
|
|
"setTippy(initVideoMirrorBtn, 'Toggle video mirror', 'top');":
|
|
"setTippy(initVideoMirrorBtn, '镜像画面', 'top');",
|
|
"setTippy(initUsernameEmojiButton, 'Toggle username emoji', 'top');":
|
|
"setTippy(initUsernameEmojiButton, '昵称表情', 'top');",
|
|
"setTippy(initExitBtn, 'Leave meeting', 'top');":
|
|
"setTippy(initExitBtn, '离开', 'top');",
|
|
"setTippy(initAudioBtn, 'Stop the audio', 'top');":
|
|
"setTippy(initAudioBtn, '关闭麦克风', 'top');",
|
|
"setTippy(initVideoBtn, 'Stop the video', 'top');":
|
|
"setTippy(initVideoBtn, '关闭摄像头', 'top');",
|
|
"setTippy(audioBtn, useAudio ? 'Stop the audio (A)' : 'My audio is disabled', bottomButtonsPlacement);":
|
|
"setTippy(audioBtn, useAudio ? '关闭麦克风 (A)' : '麦克风不可用', bottomButtonsPlacement);",
|
|
"setTippy(videoBtn, useVideo ? 'Stop the video (V)' : 'My video is disabled', bottomButtonsPlacement);":
|
|
"setTippy(videoBtn, useVideo ? '关闭摄像头 (V)' : '摄像头不可用', bottomButtonsPlacement);",
|
|
"setTippy(screenShareBtn, 'Start screen sharing (S)', bottomButtonsPlacement);":
|
|
"setTippy(screenShareBtn, '开始共享屏幕 (S)', bottomButtonsPlacement);",
|
|
"setTippy(myHandBtn, 'Raise your hand (H)', bottomButtonsPlacement);":
|
|
"setTippy(myHandBtn, '举手 (H)', bottomButtonsPlacement);",
|
|
"setTippy(chatRoomBtn, 'Open the chat (C)', bottomButtonsPlacement);":
|
|
"setTippy(chatRoomBtn, '打开聊天 (C)', bottomButtonsPlacement);",
|
|
"setTippy(participantsBtn, 'Show participants', bottomButtonsPlacement);":
|
|
"setTippy(participantsBtn, '参与者', bottomButtonsPlacement);",
|
|
"setTippy(mySettingsBtn, 'Open the settings (O)', bottomButtonsPlacement);":
|
|
"setTippy(mySettingsBtn, '设置 (O)', bottomButtonsPlacement);",
|
|
"setTippy(leaveRoomBtn, 'Leave this room', bottomButtonsPlacement);":
|
|
"setTippy(leaveRoomBtn, '离开房间', bottomButtonsPlacement);",
|
|
"title: 'Share the room'": "title: '分享房间'",
|
|
}
|
|
for a, b in reps.items():
|
|
text = text.replace(a, b)
|
|
return text
|
|
|
|
|
|
def patch_client_html(text: str) -> str:
|
|
# remove leftover English comment
|
|
text = text.replace(
|
|
"<!-- <p>Please allow the camera & microphone access to use this app.</p> -->",
|
|
"<!-- nomadro: camera permission hint is in loadingDiv -->",
|
|
)
|
|
if "nomadro-i18n.js" not in text:
|
|
text = text.replace(
|
|
'<link rel="stylesheet" href="../css/nomadro-embed.css" />',
|
|
'<link rel="stylesheet" href="../css/nomadro-embed.css" />\n'
|
|
' <script src="../js/nomadro-i18n.js"></script>',
|
|
1,
|
|
)
|
|
if "nomadro-i18n.js" not in text:
|
|
# css link may already exist without exact match — inject before </head>
|
|
text = text.replace(
|
|
"</head>",
|
|
' <link rel="stylesheet" href="../css/nomadro-embed.css" />\n'
|
|
' <script src="../js/nomadro-i18n.js"></script>\n'
|
|
" </head>",
|
|
1,
|
|
)
|
|
# disable google translate loader for CN reliability (hardcoded zh instead)
|
|
text = text.replace(
|
|
'<script async src="../js/translate.js"></script>',
|
|
"<!-- nomadro: translate.js disabled; zh-CN hardcoded via nomadro-i18n.js -->",
|
|
)
|
|
text = text.replace('<html lang="en">', '<html lang="zh-CN">')
|
|
return text
|
|
|
|
|
|
def patch_translate_disable(text: str) -> str:
|
|
# Keep file but no-op so accidental loads don't pull Google
|
|
if "nomadro: disabled" in text:
|
|
return text
|
|
return (
|
|
"'use strict';\n"
|
|
"// nomadro: disabled Google Translate (CN). UI strings are zh-CN in HTML/JS.\n"
|
|
"console.info('[nomadro] translate.js noop');\n"
|
|
)
|
|
|
|
|
|
def main() -> int:
|
|
c = ssh()
|
|
print("connected")
|
|
|
|
write(c, f"{BASE}/public/css/nomadro-embed.css", (HERE / "nomadro-embed.css").read_text(encoding="utf-8"))
|
|
write(c, f"{BASE}/public/js/nomadro-i18n.js", (HERE / "nomadro-i18n.js").read_text(encoding="utf-8"))
|
|
print("assets uploaded")
|
|
|
|
for remote, fn in [
|
|
(f"{BASE}/public/js/client.js", patch_client_js),
|
|
(f"{BASE}/public/views/client.html", patch_client_html),
|
|
(f"{BASE}/public/js/translate.js", patch_translate_disable),
|
|
]:
|
|
out, code = run(c, f"sudo cat {remote}")
|
|
if code != 0:
|
|
print("fail", remote)
|
|
return 1
|
|
new = fn(out)
|
|
if new != out:
|
|
write(c, remote, new)
|
|
print("patched", remote)
|
|
else:
|
|
print("unchanged", remote)
|
|
|
|
# Ensure config language stays zh-CN
|
|
out, _ = run(c, f"sudo cat {BASE}/app/src/config.js")
|
|
if "language: 'zh-CN'" not in out:
|
|
out2 = out.replace("language: 'en'", "language: 'zh-CN'", 1).replace(
|
|
"name: 'MiroTalk'", "name: 'nomadro'", 1
|
|
)
|
|
write(c, f"{BASE}/app/src/config.js", out2)
|
|
print("config language fixed")
|
|
|
|
out, code = run(c, "sudo systemctl restart mirotalk-p2p && sleep 2 && systemctl is-active mirotalk-p2p")
|
|
print(out.strip())
|
|
|
|
smoke, _ = run(
|
|
c,
|
|
"curl -s 'http://127.0.0.1:9300/join?room=t&name=%E6%B8%B8%E6%B0%91¬ify=0' | "
|
|
"grep -oE '正在进入活动厅|nomadro-i18n.js|nomadro-embed.css|Please allow the camera|Join meeting|输入昵称' | sort -u",
|
|
)
|
|
print("smoke:\n", smoke)
|
|
|
|
# public edge
|
|
pub, _ = run(
|
|
c,
|
|
"curl -sk 'https://mirotalk.nomadro.com/join?room=t&name=test¬ify=0' | "
|
|
"grep -oE '正在进入活动厅|nomadro-i18n.js|Please allow the camera' | sort -u",
|
|
)
|
|
print("public:\n", pub)
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|