@nestim/koishi-plugin-qqgm-webui 0.2.8 → 0.2.10
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/README.md +6 -2
- package/index.js +41 -5
- package/package.json +1 -1
- package/public/app.js +25 -0
- package/public/index.html +5 -1
- package/public/styles.css +6 -0
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
# qqgm-webui
|
|
1
|
+
# qqgm-webui(0.2.8)
|
|
2
2
|
|
|
3
|
-
QQGM
|
|
3
|
+
QQGM 附属插件的图形化管理台。
|
|
4
|
+
|
|
5
|
+
- 首页、插件、监控、记忆页已接**真实只读 API**(监控 SQLite、记忆 SQLite、插件扫描);
|
|
6
|
+
- 配置写入、一键安装、完整日志 sink 还没接;
|
|
7
|
+
- 默认只在 `/qqgm` 提供页面,公网访问必须设置 token。
|
|
4
8
|
|
|
5
9
|

|
|
6
10
|
|
package/index.js
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
const fs = require('node:fs');
|
|
8
8
|
const path = require('node:path');
|
|
9
|
+
const { execFile } = require('node:child_process');
|
|
10
|
+
const { promisify } = require('node:util');
|
|
9
11
|
const { Schema } = require('koishi');
|
|
10
12
|
const { pluginList, monitor, memory } = require('./lib/data');
|
|
13
|
+
const run = promisify(execFile);
|
|
11
14
|
|
|
12
15
|
const name = 'qqgm-webui';
|
|
13
16
|
const inject = ['server'];
|
|
@@ -17,6 +20,7 @@ const Config = Schema.object({
|
|
|
17
20
|
route: Schema.string().default('/qqgm').description('挂载路径,需以 / 开头。'),
|
|
18
21
|
token: Schema.string().default('').description('访问令牌;公网必须设置。'),
|
|
19
22
|
allowRemote: Schema.boolean().default(false).description('是否允许非本机访问。'),
|
|
23
|
+
allowInstall: Schema.boolean().default(true).description('允许一键安装 @nestim 附属插件(npm install)。'),
|
|
20
24
|
});
|
|
21
25
|
|
|
22
26
|
const TYPES = {
|
|
@@ -94,7 +98,7 @@ function apply(ctx, config) {
|
|
|
94
98
|
ctx.server.get(`${route}/api/health`, (koa) => json(koa, {
|
|
95
99
|
ok: true,
|
|
96
100
|
name,
|
|
97
|
-
version: '0.2.
|
|
101
|
+
version: '0.2.10',
|
|
98
102
|
route,
|
|
99
103
|
tokenRequired: !!config.token,
|
|
100
104
|
remoteAllowed: !!config.allowRemote,
|
|
@@ -128,10 +132,42 @@ function apply(ctx, config) {
|
|
|
128
132
|
});
|
|
129
133
|
|
|
130
134
|
// 写操作下一阶段:需要 token + 备份 + schema 校验。
|
|
131
|
-
ctx.server.post(`${route}/api/install`, (koa) =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
ctx.server.post(`${route}/api/install`, async (koa) => {
|
|
136
|
+
if (!guard(koa)) return;
|
|
137
|
+
if (!config.allowInstall) {
|
|
138
|
+
koa.status = 403;
|
|
139
|
+
koa.body = { ok: false, error: 'install disabled' };
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
let body = {};
|
|
143
|
+
try {
|
|
144
|
+
let raw = '';
|
|
145
|
+
for await (const chunk of koa.req) raw += chunk;
|
|
146
|
+
body = raw ? JSON.parse(raw) : {};
|
|
147
|
+
} catch { /* invalid body */ }
|
|
148
|
+
const pkg = String(body.package || '');
|
|
149
|
+
if (!/^@nestim\/koishi-plugin-[a-z0-9-]+$/.test(pkg)) {
|
|
150
|
+
koa.status = 400;
|
|
151
|
+
koa.body = { ok: false, error: 'only @nestim/koishi-plugin-* packages are allowed' };
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const result = await run('npm', ['install', pkg, '--no-audit', '--no-fund'], {
|
|
156
|
+
cwd: ctx.baseDir || process.cwd(),
|
|
157
|
+
timeout: 120_000,
|
|
158
|
+
windowsHide: true,
|
|
159
|
+
});
|
|
160
|
+
koa.body = {
|
|
161
|
+
ok: true,
|
|
162
|
+
package: pkg,
|
|
163
|
+
restartRequired: true,
|
|
164
|
+
output: String(result.stdout || '').slice(-2000),
|
|
165
|
+
};
|
|
166
|
+
} catch (error) {
|
|
167
|
+
koa.status = 500;
|
|
168
|
+
koa.body = { ok: false, error: String(error && error.message || error) };
|
|
169
|
+
}
|
|
170
|
+
});
|
|
135
171
|
|
|
136
172
|
logger.info(`WebUI 已挂载:${route}(token=${config.token ? '已设置' : '未设置'})`);
|
|
137
173
|
}
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -24,6 +24,11 @@ function showToast(text) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function go(page) {
|
|
27
|
+
const monitorNav = $('.nav-item[data-page="monitor"]');
|
|
28
|
+
if (page === 'monitor' && monitorNav && monitorNav.classList.contains('disabled')) {
|
|
29
|
+
showToast('安装 qqgm-monitor 后可用');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
27
32
|
$$('.nav-item').forEach((item) => item.classList.toggle('active', item.dataset.page === page));
|
|
28
33
|
$$('.nav-sub').forEach((item) => item.classList.toggle('active', item.dataset.page === page));
|
|
29
34
|
$$('.page').forEach((item) => item.classList.toggle('active', item.id === `page-${page}`));
|
|
@@ -57,6 +62,8 @@ function setMonitorState(on) {
|
|
|
57
62
|
if (!monitor || !welcome) return;
|
|
58
63
|
monitor.hidden = !on;
|
|
59
64
|
welcome.hidden = on;
|
|
65
|
+
const nav = $('.nav-item[data-page="monitor"]');
|
|
66
|
+
if (nav) nav.classList.toggle('disabled', !on);
|
|
60
67
|
const title = $('#pageTitle');
|
|
61
68
|
if (title) title.textContent = '总览';
|
|
62
69
|
}
|
|
@@ -139,6 +146,24 @@ async function initMemoryData() {
|
|
|
139
146
|
}
|
|
140
147
|
initMemoryData();
|
|
141
148
|
|
|
149
|
+
async function installPackage(pkg) {
|
|
150
|
+
const token = new URLSearchParams(location.search).get('token') || '';
|
|
151
|
+
showToast(`正在安装 ${pkg}…`);
|
|
152
|
+
try {
|
|
153
|
+
const res = await fetch(`api/install${token ? `?token=${encodeURIComponent(token)}` : ''}`, {
|
|
154
|
+
method: 'POST',
|
|
155
|
+
headers: { 'content-type': 'application/json' },
|
|
156
|
+
body: JSON.stringify({ package: pkg }),
|
|
157
|
+
});
|
|
158
|
+
const data = await res.json();
|
|
159
|
+
if (!res.ok || !data.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
|
160
|
+
showToast('安装完成,重启/重载插件后生效');
|
|
161
|
+
} catch (error) {
|
|
162
|
+
showToast(`安装失败:${String(error.message || error)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
$('#installMonitor')?.addEventListener('click', () => installPackage('@nestim/koishi-plugin-qqgm-monitor'));
|
|
166
|
+
|
|
142
167
|
// memory backend note
|
|
143
168
|
const memoryNote = $('#memoryBackend');
|
|
144
169
|
if (memoryNote) {
|
package/public/index.html
CHANGED
|
@@ -191,13 +191,17 @@
|
|
|
191
191
|
<h1>欢迎使用 QQGM</h1>
|
|
192
192
|
<p>主插件已经连上了,但还没有安装监控插件。<br />首页暂时只能看到基础状态;装好监控后,这里会自动变成运行总览。</p>
|
|
193
193
|
<div class="welcome-actions">
|
|
194
|
-
<button class="btn primary"
|
|
194
|
+
<button class="btn primary" id="installMonitor">一键安装监控</button>
|
|
195
195
|
<a class="btn ghost" href="https://github.com/Miseat/koishi-plugin-qqgm-monitor" target="_blank" rel="noreferrer">GitHub</a>
|
|
196
196
|
<a class="btn ghost" href="https://www.npmjs.com/package/@nestim/koishi-plugin-qqgm-monitor" target="_blank" rel="noreferrer">npm</a>
|
|
197
197
|
<button class="link-btn" id="demoMonitor">预览:已装监控 →</button>
|
|
198
198
|
</div>
|
|
199
199
|
</div>
|
|
200
200
|
|
|
201
|
+
<div class="welcome-status">
|
|
202
|
+
<div><span class="pulse"></span><b>主插件已连接</b><span>v1.6.0 · 作者 Miseat</span></div>
|
|
203
|
+
<div>已安装 6 个附属插件 · 监控未安装</div>
|
|
204
|
+
</div>
|
|
201
205
|
<div class="welcome-grid">
|
|
202
206
|
<article class="card welcome-card">
|
|
203
207
|
<span class="step">01</span>
|
package/public/styles.css
CHANGED
|
@@ -46,6 +46,8 @@ svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round
|
|
|
46
46
|
.nav-item:hover { color: #e8eefb; background: rgba(255,255,255,.045); }
|
|
47
47
|
.nav-item.active { color: #fff; background: linear-gradient(90deg, rgba(79,125,243,.24), rgba(79,125,243,.08)); box-shadow: inset 2px 0 0 #5b8def; }
|
|
48
48
|
.nav-item.active svg { color: #8fb0ff; }
|
|
49
|
+
.nav-item.disabled { opacity: .35; cursor: not-allowed; }
|
|
50
|
+
.nav-item.disabled:hover { background: none; color: #93a1b8; }
|
|
49
51
|
.nav-badge { margin-left: auto; font-style: normal; font-size: 10.5px; background: #1c2b42; color: #9fb4d6; border-radius: 20px; padding: 2px 7px; }
|
|
50
52
|
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: #2dd4bf; margin-left: auto; box-shadow: 0 0 0 4px rgba(45,212,191,.12); }
|
|
51
53
|
.sidebar-footer { position: absolute; left: 14px; right: 14px; bottom: 16px; border-top: 1px solid rgba(255,255,255,.07); padding-top: 11px; background: var(--nav); }
|
|
@@ -273,6 +275,10 @@ code { background: #f2f5f9; color: #55657d; border-radius: 4px; padding: 1px 4px
|
|
|
273
275
|
.welcome-actions .btn.primary { background: #fff; color: #1b3154; box-shadow: none; }
|
|
274
276
|
.welcome-actions .link-btn { color: #9dbcf0; margin-left: 4px; }
|
|
275
277
|
.welcome-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
|
|
278
|
+
.welcome-status { display: flex; justify-content: space-between; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 10.5px; color: #8796aa; }
|
|
279
|
+
.welcome-status div { display: flex; align-items: center; gap: 8px; }
|
|
280
|
+
.welcome-status b { color: #3e4e65; font-weight: 600; }
|
|
281
|
+
.welcome-status .pulse { width: 6px; height: 6px; }
|
|
276
282
|
.welcome-card { position: relative; padding: 18px; }
|
|
277
283
|
.welcome-card .step { font-size: 10px; letter-spacing: .1em; color: #8fa3bd; }
|
|
278
284
|
.welcome-card h3 { margin: 8px 0 6px; font-size: 14px; }
|