@nestim/koishi-plugin-qqgm-webui 0.2.8 → 0.2.9
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 +18 -0
- package/public/index.html +1 -1
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.9',
|
|
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
|
@@ -139,6 +139,24 @@ async function initMemoryData() {
|
|
|
139
139
|
}
|
|
140
140
|
initMemoryData();
|
|
141
141
|
|
|
142
|
+
async function installPackage(pkg) {
|
|
143
|
+
const token = new URLSearchParams(location.search).get('token') || '';
|
|
144
|
+
showToast(`正在安装 ${pkg}…`);
|
|
145
|
+
try {
|
|
146
|
+
const res = await fetch(`api/install${token ? `?token=${encodeURIComponent(token)}` : ''}`, {
|
|
147
|
+
method: 'POST',
|
|
148
|
+
headers: { 'content-type': 'application/json' },
|
|
149
|
+
body: JSON.stringify({ package: pkg }),
|
|
150
|
+
});
|
|
151
|
+
const data = await res.json();
|
|
152
|
+
if (!res.ok || !data.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
|
153
|
+
showToast('安装完成,重启/重载插件后生效');
|
|
154
|
+
} catch (error) {
|
|
155
|
+
showToast(`安装失败:${String(error.message || error)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
$('#installMonitor')?.addEventListener('click', () => installPackage('@nestim/koishi-plugin-qqgm-monitor'));
|
|
159
|
+
|
|
142
160
|
// memory backend note
|
|
143
161
|
const memoryNote = $('#memoryBackend');
|
|
144
162
|
if (memoryNote) {
|
package/public/index.html
CHANGED
|
@@ -191,7 +191,7 @@
|
|
|
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>
|