@nestim/koishi-plugin-qqgm-webui 0.2.2 → 0.2.4

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/index.js CHANGED
@@ -81,7 +81,11 @@ function apply(ctx, config) {
81
81
  koa.body = value;
82
82
  };
83
83
 
84
- ctx.server.get(route, (koa) => sendFile(koa, 'index.html'));
84
+ ctx.server.get(route, (koa) => {
85
+ if (!guard(koa)) return;
86
+ const qs = koa.querystring ? `?${koa.querystring}` : '';
87
+ koa.redirect(`${route}/${qs}`);
88
+ });
85
89
  ctx.server.get(`${route}/`, (koa) => sendFile(koa, 'index.html'));
86
90
  ctx.server.get(`${route}/styles.css`, (koa) => sendFile(koa, 'styles.css'));
87
91
  ctx.server.get(`${route}/app.js`, (koa) => sendFile(koa, 'app.js'));
@@ -89,7 +93,7 @@ function apply(ctx, config) {
89
93
  ctx.server.get(`${route}/api/health`, (koa) => json(koa, {
90
94
  ok: true,
91
95
  name,
92
- version: '0.2.2',
96
+ version: '0.2.4',
93
97
  route,
94
98
  tokenRequired: !!config.token,
95
99
  remoteAllowed: !!config.allowRemote,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestim/koishi-plugin-qqgm-webui",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "QQGM 附属 WebUI:插件识别、监控看板、记忆库、配置与日志。",
5
5
  "main": "index.js",
6
6
  "files": [
package/public/app.js CHANGED
@@ -92,6 +92,35 @@ async function initRealData() {
92
92
  }
93
93
  initRealData();
94
94
 
95
+ async function initMemoryData() {
96
+ try {
97
+ const token = new URLSearchParams(location.search).get('token') || '';
98
+ const res = await fetch(`api/memory?limit=20${token ? `&token=${encodeURIComponent(token)}` : ''}`, { cache: 'no-store' });
99
+ if (!res.ok) return;
100
+ const data = await res.json();
101
+ if (!data || !data.installed) return;
102
+ const badge = $('.nav-badge');
103
+ if (badge) badge.textContent = String(data.total || 0);
104
+ const list = $('#memoryList');
105
+ if (!list) return;
106
+ if (!data.items.length) {
107
+ list.innerHTML = '<div class="memory-empty"><b>还没有记忆</b><p>主插件当前使用 MD 后端,或 SQLite 里还没有数据。<br>切到 SQLite 并执行 <code>memdb migrate</code> 后会出现在这里。</p></div>';
108
+ return;
109
+ }
110
+ list.innerHTML = data.items.map((item) => `
111
+ <article class="memory-item">
112
+ <div class="memory-head">
113
+ <span class="tag ${item.scope_kind === 'private' ? 'private' : 'group'}">${item.scope_kind === 'group' ? '群' : item.scope_kind === 'private' ? '私聊' : '全局'} ${item.scope_id || ''}</span>
114
+ <span class="tag soft">${item.category || '未分类'}</span>
115
+ <time>${new Date(item.created_at).toLocaleString('zh-CN', { hour12: false })}</time>
116
+ </div>
117
+ <p>${String(item.content || '').replace(/[<>&]/g, (c) => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;' }[c]))}</p>
118
+ <div class="memory-foot"><code>${item.label || '记忆'}</code><span>#${item.id}</span></div>
119
+ </article>`).join('');
120
+ } catch { /* 文件预览保留 mock */ }
121
+ }
122
+ initMemoryData();
123
+
95
124
  // memory backend note
96
125
  const memoryNote = $('#memoryBackend');
97
126
  if (memoryNote) {
package/public/styles.css CHANGED
@@ -257,6 +257,9 @@ code { background: #f2f5f9; color: #55657d; border-radius: 4px; padding: 1px 4px
257
257
  .statusbar .pulse { width: 5px; height: 5px; margin-right: 5px; }
258
258
  .memory-note { background: #fff8e8; border: 1px solid #f3e4c4; color: #8d7138; font-size: 10.5px; line-height: 1.55; padding: 8px 11px; border-radius: 8px; margin: -8px 0 14px; }
259
259
  .memory-note b { color: #775c24; }
260
+ .memory-empty { text-align: center; padding: 44px 20px; color: #7d8b9f; }
261
+ .memory-empty b { display: block; font-size: 14px; color: #45556b; margin-bottom: 7px; }
262
+ .memory-empty p { margin: 0; font-size: 11px; line-height: 1.7; }
260
263
  .overview-meta { text-align: right; color: #a5b1c2; font-size: 9.5px; padding: 4px 2px 0; letter-spacing: .01em; }
261
264
 
262
265
  /* welcome / no monitor */