@wendongfly/myhi 1.3.180 → 1.3.181

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/chat.html +11 -2
  2. package/package.json +1 -1
package/dist/chat.html CHANGED
@@ -1380,7 +1380,7 @@
1380
1380
  list.innerHTML = '<div style="padding:0.6rem;color:var(--muted);font-size:0.75rem">读取中…</div>';
1381
1381
  try {
1382
1382
  const r = await fetch('/api/dirs' + (path ? '?path=' + encodeURIComponent(path) : ''));
1383
- const d = await r.json();
1383
+ const d = await readApiJson(r);
1384
1384
  if (!r.ok) throw new Error(d.error || r.status);
1385
1385
  _atPick = d;
1386
1386
  const cur = document.getElementById('atpick-cur');
@@ -2415,6 +2415,15 @@
2415
2415
  scrollToBottom();
2416
2416
  }
2417
2417
 
2418
+ // 解析接口 JSON。升级后没重启 server 时,新页面调新接口会拿到 Express 的 404 HTML,
2419
+ // 直接 .json() 只报「Unexpected token '<'」,用户看不懂 → 换成明确的处理建议
2420
+ async function readApiJson(resp) {
2421
+ const text = await resp.text();
2422
+ try { return JSON.parse(text); } catch {}
2423
+ if (resp.status === 404 || /^\s*</.test(text)) throw new Error('服务端还是旧版本——升级后需要重启 myhi(设置→更多→重启 myhi)');
2424
+ throw new Error(`服务端返回异常(HTTP ${resp.status})`);
2425
+ }
2426
+
2418
2427
  // 复制到剪贴板。HTTP 访问(非安全上下文)没有 navigator.clipboard,退回 textarea + execCommand
2419
2428
  async function copyText(text) {
2420
2429
  try {
@@ -4098,7 +4107,7 @@
4098
4107
  headers: { 'Content-Type': 'application/json' },
4099
4108
  body: JSON.stringify({ name: document.getElementById('set-machine-name').value.trim() }),
4100
4109
  });
4101
- const data = await resp.json();
4110
+ const data = await readApiJson(resp);
4102
4111
  if (!data.ok) throw new Error(data.error || '未知错误');
4103
4112
  window.myhiSetMachineName?.(data.name);
4104
4113
  statusEl.style.color = 'var(--green)';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wendongfly/myhi",
3
- "version": "1.3.180",
3
+ "version": "1.3.181",
4
4
  "description": "Web-based terminal sharing with chat UI — control your terminal from phone via LAN/Tailscale",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",