@wendongfly/myhi 1.3.16 → 1.3.17

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.
package/dist/chat.html CHANGED
@@ -272,7 +272,7 @@
272
272
  <span class="sb-item" id="work-status"><span class="sb-dot idle"></span> 空闲</span>
273
273
  <span id="control-badge" class="readonly" style="display:none">只读</span>
274
274
  <span id="viewer-count" class="sb-item"></span>
275
- <span id="update-badge" style="display:none;color:#d29922;cursor:pointer" onclick="location.href='/'">⬆ 有更新</span>
275
+ <span id="update-badge" style="display:none;color:#d29922;cursor:pointer" onclick="doUpdate()">⬆ 有更新</span>
276
276
  </div>
277
277
 
278
278
  <div id="chat-area"></div>
@@ -2517,15 +2517,51 @@
2517
2517
  cmdInput.focus();
2518
2518
 
2519
2519
  // ── 版本更新检查 ──────────────────────────────
2520
+ let _versionInfo = null;
2520
2521
  (async function checkUpdate() {
2521
2522
  try {
2522
2523
  const resp = await fetch('/api/version');
2523
2524
  if (!resp.ok) return;
2524
- const data = await resp.json();
2525
- if (data.updateAvailable) document.getElementById('update-badge').style.display = '';
2525
+ _versionInfo = await resp.json();
2526
+ const badge = document.getElementById('update-badge');
2527
+ if (_versionInfo.updateAvailable) {
2528
+ badge.textContent = `⬆ ${_versionInfo.latest}`;
2529
+ badge.style.display = '';
2530
+ } else {
2531
+ badge.style.display = 'none';
2532
+ }
2526
2533
  } catch {}
2527
2534
  setTimeout(checkUpdate, 10 * 60 * 1000);
2528
2535
  })();
2536
+
2537
+ window.doUpdate = async function() {
2538
+ if (!_versionInfo?.updateAvailable) return;
2539
+ if (!confirm(`更新 myhi?\n当前: ${_versionInfo.current}\n最新: ${_versionInfo.latest}\n\n更新后服务将自动重启`)) return;
2540
+ const badge = document.getElementById('update-badge');
2541
+ badge.textContent = '⬆ 更新中...';
2542
+ badge.style.color = '#8b949e';
2543
+ try {
2544
+ const resp = await fetch('/api/update', { method: 'POST' });
2545
+ const data = await resp.json();
2546
+ addStatusMessage(data.message || '升级中...');
2547
+ badge.textContent = '⬆ 重启中...';
2548
+ // 等待服务重启后自动刷新
2549
+ setTimeout(() => {
2550
+ let retries = 0;
2551
+ const poll = setInterval(async () => {
2552
+ try {
2553
+ const r = await fetch('/api/version');
2554
+ if (r.ok) { clearInterval(poll); location.reload(); }
2555
+ } catch {}
2556
+ if (++retries > 30) { clearInterval(poll); badge.textContent = '⬆ 请手动刷新'; badge.style.color = '#f85149'; }
2557
+ }, 3000);
2558
+ }, 5000);
2559
+ } catch (e) {
2560
+ addStatusMessage('更新失败: ' + e.message);
2561
+ badge.textContent = `⬆ ${_versionInfo.latest}`;
2562
+ badge.style.color = '#d29922';
2563
+ }
2564
+ };
2529
2565
  </script>
2530
2566
  </body>
2531
2567
  </html>