@nestim/koishi-plugin-qqgm-webui 0.2.18 → 0.2.19
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 +2 -1
- package/lib/data.js +2 -1
- package/package.json +1 -1
- package/public/app.js +47 -19
package/index.js
CHANGED
|
@@ -115,7 +115,7 @@ function apply(ctx, config) {
|
|
|
115
115
|
ctx.server.get(`${route}/api/health`, (koa) => json(koa, {
|
|
116
116
|
ok: true,
|
|
117
117
|
name,
|
|
118
|
-
version: '0.2.
|
|
118
|
+
version: '0.2.19',
|
|
119
119
|
route,
|
|
120
120
|
tokenRequired: !!config.token,
|
|
121
121
|
remoteAllowed: !!config.allowRemote,
|
|
@@ -157,6 +157,7 @@ function apply(ctx, config) {
|
|
|
157
157
|
json(koa, memory(ctx, {
|
|
158
158
|
scope: koa.query.scope || '',
|
|
159
159
|
query: koa.query.q || '',
|
|
160
|
+
category: koa.query.category || '',
|
|
160
161
|
limit: koa.query.limit || 50,
|
|
161
162
|
}));
|
|
162
163
|
});
|
package/lib/data.js
CHANGED
|
@@ -152,7 +152,7 @@ function parseScope(text) {
|
|
|
152
152
|
return { kind: 'group', id: value };
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
function memory(ctx, { scope = '', query = '', limit = 50 } = {}) {
|
|
155
|
+
function memory(ctx, { scope = '', query = '', category = '', limit = 50 } = {}) {
|
|
156
156
|
const base = ctx.baseDir || process.cwd();
|
|
157
157
|
const file = path.join(base, 'data', 'qqgm-memory.sqlite');
|
|
158
158
|
const cfg = readMemoryConfig(ctx);
|
|
@@ -177,6 +177,7 @@ function memory(ctx, { scope = '', query = '', limit = 50 } = {}) {
|
|
|
177
177
|
const parsed = parseScope(scope);
|
|
178
178
|
let filtered = source;
|
|
179
179
|
if (parsed) filtered = filtered.filter((item) => item.scope_kind === parsed.kind && String(item.scope_id) === String(parsed.id));
|
|
180
|
+
if (category) filtered = filtered.filter((item) => (item.category || '未分类') === category);
|
|
180
181
|
if (query) filtered = filtered.filter((item) => String(item.content).includes(query) || String(item.label || '').includes(query));
|
|
181
182
|
const items = filtered.slice(0, Math.max(1, Math.min(200, Number(limit) || 50)));
|
|
182
183
|
const scopes = new Map();
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -117,6 +117,42 @@ initRealData();
|
|
|
117
117
|
let memoryItems = [];
|
|
118
118
|
let memoryState = null;
|
|
119
119
|
|
|
120
|
+
function renderMemoryList(items) {
|
|
121
|
+
memoryItems = items || [];
|
|
122
|
+
const list = $('#memoryList');
|
|
123
|
+
if (!list) return;
|
|
124
|
+
if (!memoryItems.length) {
|
|
125
|
+
list.innerHTML = '<div class="memory-empty"><b>没有匹配的记忆</b><p>换个范围/分类,或先迁移 MD 到 SQLite。</p></div>';
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
list.innerHTML = memoryItems.map((item, index) => `
|
|
129
|
+
<article class="memory-item" data-memory-index="${index}">
|
|
130
|
+
<div class="memory-head">
|
|
131
|
+
<span class="tag ${item.scope_kind === 'private' ? 'private' : 'group'}">${item.scope_kind === 'group' ? '群' : item.scope_kind === 'private' ? '私聊' : '全局'} ${item.scope_id || ''}</span>
|
|
132
|
+
<span class="tag soft">${item.category || '未分类'}</span>
|
|
133
|
+
<time>${new Date(item.created_at).toLocaleString('zh-CN', { hour12: false })}</time>
|
|
134
|
+
</div>
|
|
135
|
+
<p>${String(item.content || '').replace(/[<>&]/g, (c) => ({ '<': '<', '>': '>', '&': '&' }[c]))}</p>
|
|
136
|
+
<div class="memory-foot"><code>${item.label || '记忆'}</code><span>#${item.id}</span><span class="memory-open">点击查看</span></div>
|
|
137
|
+
</article>`).join('');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function filterMemory(scope, category, activeButton) {
|
|
141
|
+
const params = new URLSearchParams({ limit: '200' });
|
|
142
|
+
if (scope) params.set('scope', scope);
|
|
143
|
+
if (category) params.set('category', category);
|
|
144
|
+
const token = new URLSearchParams(location.search).get('token') || '';
|
|
145
|
+
if (token) params.set('token', token);
|
|
146
|
+
try {
|
|
147
|
+
const res = await fetch(`api/memory?${params}`, { cache: 'no-store' });
|
|
148
|
+
if (!res.ok) return;
|
|
149
|
+
const data = await res.json();
|
|
150
|
+
renderMemoryList(data.items || []);
|
|
151
|
+
$$('#memoryScopes .scope').forEach((btn) => btn.classList.remove('active'));
|
|
152
|
+
if (activeButton) activeButton.classList.add('active');
|
|
153
|
+
} catch { showToast('筛选失败'); }
|
|
154
|
+
}
|
|
155
|
+
|
|
120
156
|
async function initMemoryData() {
|
|
121
157
|
try {
|
|
122
158
|
const token = new URLSearchParams(location.search).get('token') || '';
|
|
@@ -157,37 +193,29 @@ async function initMemoryData() {
|
|
|
157
193
|
}
|
|
158
194
|
const scopes = $('#memoryScopes');
|
|
159
195
|
if (scopes) {
|
|
160
|
-
const scopeButtons = [`<h3>范围</h3><button class="scope active"><span>全部</span><b>${data.total || 0}</b></button>`];
|
|
196
|
+
const scopeButtons = [`<h3>范围</h3><button class="scope active" data-scope="" data-category=""><span>全部</span><b>${data.total || 0}</b></button>`];
|
|
161
197
|
for (const item of data.scopes || []) {
|
|
162
198
|
const label = item.scope_kind === 'group' ? `群 ${item.scope_id}` : item.scope_kind === 'private' ? `私聊 ${item.scope_id}` : `全局 ${item.scope_id || ''}`;
|
|
163
|
-
scopeButtons.push(`<button class="scope"><span>${label}</span><b>${item.n}</b></button>`);
|
|
199
|
+
scopeButtons.push(`<button class="scope" data-scope="${item.scope_kind}:${item.scope_id || ''}"><span>${label}</span><b>${item.n}</b></button>`);
|
|
164
200
|
}
|
|
165
201
|
scopeButtons.push('<h3 class="mt">分类</h3>');
|
|
166
202
|
for (const item of data.categories || []) {
|
|
167
|
-
scopeButtons.push(`<button class="scope"><span>${item.category}</span><b>${item.n}</b></button>`);
|
|
203
|
+
scopeButtons.push(`<button class="scope" data-category="${String(item.category).replace(/"/g, '"')}"><span>${item.category}</span><b>${item.n}</b></button>`);
|
|
168
204
|
}
|
|
169
205
|
scopes.innerHTML = scopeButtons.join('');
|
|
170
206
|
}
|
|
171
|
-
|
|
172
|
-
if (!list) return;
|
|
173
|
-
if (!data.items.length) {
|
|
174
|
-
list.innerHTML = '<div class="memory-empty"><b>还没有记忆</b><p>主插件当前使用 MD 后端,或 SQLite 里还没有数据。<br>切到 SQLite 并执行 <code>memdb migrate</code> 后会出现在这里。</p></div>';
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
list.innerHTML = data.items.map((item, index) => `
|
|
178
|
-
<article class="memory-item" data-memory-index="${index}">
|
|
179
|
-
<div class="memory-head">
|
|
180
|
-
<span class="tag ${item.scope_kind === 'private' ? 'private' : 'group'}">${item.scope_kind === 'group' ? '群' : item.scope_kind === 'private' ? '私聊' : '全局'} ${item.scope_id || ''}</span>
|
|
181
|
-
<span class="tag soft">${item.category || '未分类'}</span>
|
|
182
|
-
<time>${new Date(item.created_at).toLocaleString('zh-CN', { hour12: false })}</time>
|
|
183
|
-
</div>
|
|
184
|
-
<p>${String(item.content || '').replace(/[<>&]/g, (c) => ({ '<': '<', '>': '>', '&': '&' }[c]))}</p>
|
|
185
|
-
<div class="memory-foot"><code>${item.label || '记忆'}</code><span>#${item.id}</span><span class="memory-open">点击查看</span></div>
|
|
186
|
-
</article>`).join('');
|
|
207
|
+
renderMemoryList(data.items);
|
|
187
208
|
} catch { /* 文件预览保留 mock */ }
|
|
188
209
|
}
|
|
189
210
|
initMemoryData();
|
|
190
211
|
|
|
212
|
+
$('#memoryScopes')?.addEventListener('click', (event) => {
|
|
213
|
+
const btn = event.target.closest('.scope');
|
|
214
|
+
if (!btn) return;
|
|
215
|
+
if (btn.dataset.scope === undefined && btn.dataset.category === undefined) return;
|
|
216
|
+
filterMemory(btn.dataset.scope || '', btn.dataset.category || '', btn).catch(() => {});
|
|
217
|
+
});
|
|
218
|
+
|
|
191
219
|
function memoryScopeLabel(item) {
|
|
192
220
|
if (item.scope_kind === 'group') return `群 ${item.scope_id}`;
|
|
193
221
|
if (item.scope_kind === 'private') return `私聊 ${item.scope_id}`;
|