@kotori-bot/kotori-plugin-webui 1.1.4 → 1.3.0
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 +2 -0
- package/assets/avatar.svg +26 -0
- package/dist/index.html +71 -2
- package/lib/index.d.ts +3 -4
- package/lib/index.js +14 -14
- package/lib/plugin/index.d.ts +1 -1
- package/lib/plugin/index.js +12 -12
- package/lib/routers/api/accounts.d.ts +1 -1
- package/lib/routers/api/accounts.js +12 -15
- package/lib/routers/api/config.d.ts +1 -1
- package/lib/routers/api/config.js +26 -33
- package/lib/routers/api/data.d.ts +1 -1
- package/lib/routers/api/data.js +14 -83
- package/lib/routers/api/demo.d.ts +2 -2
- package/lib/routers/api/demo.js +4 -4
- package/lib/routers/index.d.ts +1 -1
- package/lib/routers/index.js +9 -8
- package/lib/routers/router.d.ts +1 -1
- package/lib/routers/router.js +3 -3
- package/lib/service/index.d.ts +68 -18
- package/lib/service/index.js +296 -94
- package/lib/types/index.d.ts +11 -19
- package/lib/types/index.js +3 -24
- package/lib/utils/autoSave.d.ts +2 -0
- package/lib/utils/autoSave.js +54 -0
- package/lib/utils/common.d.ts +11 -15
- package/lib/utils/common.js +27 -56
- package/lib/utils/observer.d.ts +2 -0
- package/lib/utils/observer.js +49 -0
- package/lib/utils/transport.d.ts +2 -4
- package/lib/utils/transport.js +11 -20
- package/lib/ws/index.d.ts +1 -1
- package/lib/ws/index.js +9 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -11,3 +11,5 @@ Web front end repository: [kotorijs/webui](https://github.com/kotorijs/webui)
|
|
|
11
11
|
- [x] Add authorization for websocket server
|
|
12
12
|
- [x] Login at the same time
|
|
13
13
|
- [x] Console outputting support for cmd adapter
|
|
14
|
+
- [x] Websocket verify
|
|
15
|
+
- [x] Sync offline and other data
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bgGradient" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="25%" style="stop-color:#64FFDA;stop-opacity:1" />
|
|
5
|
+
<stop offset="100%" style="stop-color:#00B0FF;stop-opacity:1" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect width="512" height="512" fill="url(#bgGradient)" />
|
|
9
|
+
|
|
10
|
+
<style>
|
|
11
|
+
.text-style {
|
|
12
|
+
dominant-baseline: middle;
|
|
13
|
+
text-anchor: middle;
|
|
14
|
+
fill: #FFFFFF;
|
|
15
|
+
font-size: 75px;
|
|
16
|
+
font-family: 'Arial', sans-serif;
|
|
17
|
+
}
|
|
18
|
+
.text-shadow {
|
|
19
|
+
filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.2));
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
|
|
23
|
+
<text x="50%" y="50%" class="text-style text-shadow " dominant-baseline="middle">
|
|
24
|
+
Kotori Plugin
|
|
25
|
+
</text>
|
|
26
|
+
</svg>
|
package/dist/index.html
CHANGED
|
@@ -4,11 +4,80 @@
|
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<
|
|
7
|
+
<link rel="icon" href="https://kotori.js.org/favicon.svg">
|
|
8
|
+
<title>Kotori Webui</title>
|
|
9
|
+
<style>
|
|
10
|
+
.container {
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
height: 95vh;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.description {
|
|
19
|
+
font-size: 1.2rem;
|
|
20
|
+
margin-top: 1rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.link {
|
|
24
|
+
font-size: 1.6rem;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.link a {
|
|
28
|
+
color: #007bff;
|
|
29
|
+
text-decoration: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.contributors li {
|
|
33
|
+
margin-bottom: 1rem;
|
|
34
|
+
font-size: 1.4rem;
|
|
35
|
+
list-style: none;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.contributors a {
|
|
39
|
+
color: #00ffdd;
|
|
40
|
+
text-decoration: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.contributors img {
|
|
44
|
+
width: 40px;
|
|
45
|
+
height: 40px;
|
|
46
|
+
border-radius: 50%;
|
|
47
|
+
margin-right: 1rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.contributors span {
|
|
51
|
+
color: #ffbd30
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
8
54
|
</head>
|
|
9
55
|
|
|
10
56
|
<body>
|
|
11
|
-
|
|
57
|
+
<div class="container">
|
|
58
|
+
<h1>👏 Hi there, Kotori Webui!</h1>
|
|
59
|
+
<span class="description"> A brand new Kotori Webui front-end - Kams (Kotori Administration Management System) is
|
|
60
|
+
under development!
|
|
61
|
+
</span>
|
|
62
|
+
<br />
|
|
63
|
+
<span class="link">Go to repository -> <a target="_blank" href="https://github.com/kotorijs/webui">here</a></span>
|
|
64
|
+
<hr />
|
|
65
|
+
<div class="contributors">
|
|
66
|
+
<h2>Web Frontend and Backend main contributors:</span>
|
|
67
|
+
<ul>
|
|
68
|
+
<li>
|
|
69
|
+
<img src="https://avatars.githubusercontent.com/u/116894525?v=4" alt="Space Pch">
|
|
70
|
+
<a target="_blank" href="https://github.com/spacepch">Painchornds</a>
|
|
71
|
+
</li>
|
|
72
|
+
<li>
|
|
73
|
+
<img src="https://avatars.githubusercontent.com/u/64067440?v=4" alt="biyuehu">
|
|
74
|
+
<a target="_blank" href="https://github.com/biyuehu">Romi</a>
|
|
75
|
+
</li>
|
|
76
|
+
</ul>
|
|
77
|
+
<h3>Thansk for all contributions!</h3>
|
|
78
|
+
<span>We are looking for more contributors to join us!</span>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
12
81
|
</body>
|
|
13
82
|
|
|
14
83
|
</html>
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Tsu } from 'kotori-bot';
|
|
2
|
-
import {
|
|
3
|
-
import { config } from './service';
|
|
1
|
+
import type { Tsu, Context } from 'kotori-bot';
|
|
2
|
+
import { type config } from './service';
|
|
4
3
|
export declare const inject: string[];
|
|
5
4
|
export declare const lang: string[];
|
|
6
|
-
export
|
|
5
|
+
export * from './service';
|
|
7
6
|
export declare function main(ctx: Context, cfg: Tsu.infer<typeof config>): void;
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/kotori-plugin-webui
|
|
4
|
-
* @Version 1.
|
|
5
|
-
* @Author Hotaru <
|
|
4
|
+
* @Version 1.3.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/
|
|
9
|
+
* @Date 2024/8/8 20:54:17
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -28,6 +28,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
28
28
|
}
|
|
29
29
|
return to;
|
|
30
30
|
};
|
|
31
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
31
32
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
33
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
34
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -39,37 +40,36 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
41
|
var src_exports = {};
|
|
41
42
|
__export(src_exports, {
|
|
42
|
-
config: () => import_service2.config,
|
|
43
43
|
inject: () => inject,
|
|
44
44
|
lang: () => lang,
|
|
45
45
|
main: () => main
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(src_exports);
|
|
48
|
-
var
|
|
49
|
-
var import_node_path = __toESM(require("node:path"));
|
|
48
|
+
var import_node_path = require("node:path");
|
|
50
49
|
var import_service = require("./service");
|
|
51
50
|
var import_routers = __toESM(require("./routers"));
|
|
52
51
|
var import_ws = __toESM(require("./ws"));
|
|
53
52
|
var import_plugin = __toESM(require("./plugin"));
|
|
54
|
-
|
|
55
|
-
const inject = ["server", "
|
|
53
|
+
__reExport(src_exports, require("./service"), module.exports);
|
|
54
|
+
const inject = ["server", "cache", "database"];
|
|
56
55
|
const lang = [__dirname, "../locales"];
|
|
57
56
|
function main(ctx, cfg) {
|
|
58
57
|
ctx.service("webui", new import_service.Webui(ctx, cfg));
|
|
59
58
|
ctx.inject("webui");
|
|
60
59
|
ctx.on("ready", () => {
|
|
61
|
-
ctx.server.wss("/webui", (ws) => {
|
|
60
|
+
ctx.server.wss("/webui/:token", (ws, { params: { token } }) => {
|
|
61
|
+
if (!ctx.webui.checkToken(token)) return ws.close(1002);
|
|
62
62
|
(0, import_ws.default)(ctx, ws);
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
const app = ctx.server;
|
|
66
|
-
app.use(app.static(import_node_path.
|
|
66
|
+
app.use(app.static((0, import_node_path.resolve)(__dirname, "../dist")));
|
|
67
67
|
app.use(app.json());
|
|
68
68
|
app.use(app.urlencoded({ extended: true }));
|
|
69
69
|
app.use("/", (0, import_routers.default)(ctx, app));
|
|
70
70
|
ctx.load({
|
|
71
|
-
|
|
72
|
-
name: (
|
|
71
|
+
// extends parent plugin's package name and share the same data files area
|
|
72
|
+
name: require("../package.json").name,
|
|
73
73
|
main: (subCtx) => {
|
|
74
74
|
(0, import_plugin.default)(subCtx);
|
|
75
75
|
}
|
|
@@ -77,8 +77,8 @@ function main(ctx, cfg) {
|
|
|
77
77
|
}
|
|
78
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
79
|
0 && (module.exports = {
|
|
80
|
-
config,
|
|
81
80
|
inject,
|
|
82
81
|
lang,
|
|
83
|
-
main
|
|
82
|
+
main,
|
|
83
|
+
...require("./service")
|
|
84
84
|
});
|
package/lib/plugin/index.d.ts
CHANGED
package/lib/plugin/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/kotori-plugin-webui
|
|
4
|
-
* @Version 1.
|
|
5
|
-
* @Author Hotaru <
|
|
4
|
+
* @Version 1.3.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/
|
|
9
|
+
* @Date 2024/8/8 20:54:17
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -35,28 +35,28 @@ module.exports = __toCommonJS(plugin_exports);
|
|
|
35
35
|
var import_types = require("../types");
|
|
36
36
|
var import_kotori_bot = require("kotori-bot");
|
|
37
37
|
var plugin_default = (ctx) => {
|
|
38
|
-
ctx.on("status", ({ status, adapter }) => {
|
|
38
|
+
ctx.on("status", async ({ status, adapter }) => {
|
|
39
|
+
if ((await ctx.webui.getVerifyHash())?.salt) return;
|
|
39
40
|
if (status !== "online") return;
|
|
40
41
|
if (adapter.platform !== "cmd") return;
|
|
41
|
-
if (ctx.webui.getVerifySalt()) return;
|
|
42
42
|
adapter.api.sendPrivateMsg(
|
|
43
|
-
(0, import_kotori_bot.formatFactory)(adapter.ctx.i18n)("webui.msg.webui.uninitialized", [adapter.config
|
|
43
|
+
(0, import_kotori_bot.formatFactory)(adapter.ctx.i18n)("webui.msg.webui.uninitialized", [adapter.config.commandPrefix]),
|
|
44
44
|
adapter.config.master
|
|
45
45
|
);
|
|
46
46
|
});
|
|
47
|
-
ctx.command("webui - webui.descr.webui").scope(import_kotori_bot.MessageScope.PRIVATE).access(import_kotori_bot.
|
|
47
|
+
ctx.filter({ test: import_kotori_bot.FilterTestList.PLATFORM, operator: "==", value: "cmd" }).command("webui - webui.descr.webui").scope(import_kotori_bot.MessageScope.PRIVATE).access(import_kotori_bot.UserAccess.ADMIN).hide().option("R", "reset:boolean webui.option.webui").action(async ({ options: { reset } }, session) => {
|
|
48
48
|
if (reset) {
|
|
49
|
-
ctx.
|
|
49
|
+
ctx.db.put("account_data", { hash: "", salt: "" });
|
|
50
50
|
return "webui.msg.webui.reset";
|
|
51
51
|
}
|
|
52
52
|
if (session.api.adapter.platform !== "cmd") return "webui.msg.webui.error";
|
|
53
|
-
if (!ctx.webui.
|
|
53
|
+
if (!(await ctx.webui.getVerifyHash()).salt) {
|
|
54
54
|
ctx.webui.setVerifyHash(
|
|
55
|
-
await session.prompt("webui.msg.webui.prompt.user"),
|
|
56
|
-
await session.prompt("webui.msg.webui.prompt.pwd")
|
|
55
|
+
(await session.prompt("webui.msg.webui.prompt.user")).toString(),
|
|
56
|
+
(await session.prompt("webui.msg.webui.prompt.pwd")).toString()
|
|
57
57
|
);
|
|
58
58
|
return "webui.msg.webui.success";
|
|
59
59
|
}
|
|
60
|
-
return
|
|
60
|
+
return session.format("webui.msg.webui", [ctx.config.global.port]);
|
|
61
61
|
});
|
|
62
62
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/kotori-plugin-webui
|
|
4
|
-
* @Version 1.
|
|
5
|
-
* @Author Hotaru <
|
|
4
|
+
* @Version 1.3.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/
|
|
9
|
+
* @Date 2024/8/8 20:54:17
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -34,22 +34,19 @@ __export(accounts_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(accounts_exports);
|
|
35
35
|
var accounts_default = (ctx, app) => {
|
|
36
36
|
const router = app.router();
|
|
37
|
-
router.post("/login", (req, res) => {
|
|
37
|
+
router.post("/login", async (req, res) => {
|
|
38
38
|
const { username, password } = req.body;
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
ctx.logger.label("
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return res.json({ token: ctx.webui.addToken() });
|
|
39
|
+
const token = await ctx.webui.accountLogin(username, password);
|
|
40
|
+
if (token) {
|
|
41
|
+
ctx.logger.label("webui").record("user login successful");
|
|
42
|
+
res.json({ token });
|
|
43
|
+
return;
|
|
45
44
|
}
|
|
46
|
-
ctx.logger.label("
|
|
47
|
-
|
|
48
|
-
ctx.webui.setLoginStats(loginStats);
|
|
49
|
-
return res.status(401).json({ message: "Invalid username or password" });
|
|
45
|
+
ctx.logger.label("webui").error("user login failed");
|
|
46
|
+
res.status(401).json({ message: "Invalid username or password" });
|
|
50
47
|
});
|
|
51
48
|
router.post("/logout", (req, res) => {
|
|
52
|
-
ctx.webui.
|
|
49
|
+
ctx.webui.accountLogout(req.headers.authorization ?? "");
|
|
53
50
|
res.sendStatus(204);
|
|
54
51
|
});
|
|
55
52
|
return router;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/kotori-plugin-webui
|
|
4
|
-
* @Version 1.
|
|
5
|
-
* @Author Hotaru <
|
|
4
|
+
* @Version 1.3.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/
|
|
9
|
+
* @Date 2024/8/8 20:54:17
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -32,48 +32,31 @@ __export(config_exports, {
|
|
|
32
32
|
default: () => config_default
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(config_exports);
|
|
35
|
-
var import_kotori_bot = require("kotori-bot");
|
|
36
35
|
var config_default = (ctx, app) => {
|
|
37
|
-
const getPluginConfig = () => Object.entries(ctx.config.plugin).map(([name, origin]) => ({ name, origin, schema: {} }));
|
|
38
|
-
const getBotConfig = () => Object.entries(ctx.config.adapter).map(([id, origin]) => ({ id, origin, schema: {} }));
|
|
39
36
|
const router = app.router();
|
|
40
37
|
router.get("/plugins/:scope?/:name?", (req, res) => {
|
|
41
38
|
const { scope, name } = req.params;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const pluginConfig = getPluginConfig().find((plugin) => plugin.name === pluginName);
|
|
45
|
-
return pluginConfig ? res.json(pluginConfig) : res.status(404).json({ message: "Plugin not found" });
|
|
39
|
+
const result = ctx.webui.configPluginsGet(scope, name);
|
|
40
|
+
return result ? res.json(result) : res.status(404).json({ message: "Plugin not found" });
|
|
46
41
|
});
|
|
47
|
-
router.put("/plugins/:scope
|
|
42
|
+
router.put("/plugins/:scope/:name?", (req, res) => {
|
|
48
43
|
const { scope, name } = req.params;
|
|
49
44
|
const { body } = req;
|
|
50
|
-
if (!scope || !name) return res.status(400).json({ message: "Invalid plugin scope" });
|
|
51
45
|
if (typeof body !== "object") return res.status(400).json({ message: "Invalid body" });
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
if (!pluginConfig) return res.status(404).json({ message: "Plugin not found" });
|
|
55
|
-
Object.keys(body).forEach((key) => {
|
|
56
|
-
if (key in pluginConfig) pluginConfig[key] = body[key];
|
|
57
|
-
});
|
|
58
|
-
return res.sendStatus(204);
|
|
46
|
+
const result = ctx.webui.configPluginUpdate(body, scope, name);
|
|
47
|
+
return result ? res.sendStatus(204) : res.status(404).json({ message: "Plugin not found" });
|
|
59
48
|
});
|
|
60
49
|
router.get("/bots/:name?", (req, res) => {
|
|
61
50
|
const { name } = req.params;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return botConfig ? res.json(botConfig) : res.status(404).json({ message: "Bot not found" });
|
|
51
|
+
const result = ctx.webui.configBotsGet(name);
|
|
52
|
+
return result ? res.json(result) : res.status(404).json({ message: "Bot not found" });
|
|
65
53
|
});
|
|
66
|
-
router.put("/bots/:name
|
|
54
|
+
router.put("/bots/:name", (req, res) => {
|
|
67
55
|
const { name } = req.params;
|
|
68
56
|
const { body } = req;
|
|
69
|
-
if (!name) return res.status(400).json({ message: "Invalid bot name" });
|
|
70
57
|
if (typeof body !== "object") return res.status(400).json({ message: "Invalid body" });
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
Object.keys(body).forEach((key) => {
|
|
74
|
-
if (key in botConfig) botConfig[key] = body[key];
|
|
75
|
-
});
|
|
76
|
-
return res.sendStatus(204);
|
|
58
|
+
const result = ctx.webui.configBotsUpdate(body, name);
|
|
59
|
+
return result ? res.sendStatus(204) : res.status(404).json({ message: "Bot not found" });
|
|
77
60
|
});
|
|
78
61
|
router.get("/global", (_, res) => {
|
|
79
62
|
res.json(ctx.config.global);
|
|
@@ -81,10 +64,20 @@ var config_default = (ctx, app) => {
|
|
|
81
64
|
router.put("/global", (req, res) => {
|
|
82
65
|
const { body } = req;
|
|
83
66
|
if (typeof body !== "object") return res.status(400).json({ message: "Invalid body" });
|
|
84
|
-
|
|
85
|
-
if (key in ctx.config.global) ctx.config.global[key] = body[key];
|
|
86
|
-
});
|
|
67
|
+
ctx.webui.configGlobalUpdate(body);
|
|
87
68
|
return res.sendStatus(204);
|
|
88
69
|
});
|
|
70
|
+
router.get("/commands/:name?", async (req, res) => {
|
|
71
|
+
const { name } = req.params;
|
|
72
|
+
const result = await ctx.webui.configCommandsGet(name);
|
|
73
|
+
return result ? res.json(result) : res.status(404).json({ message: "Command not found" });
|
|
74
|
+
});
|
|
75
|
+
router.put("/commands/:name", async (req, res) => {
|
|
76
|
+
const { name } = req.params;
|
|
77
|
+
const { body } = req;
|
|
78
|
+
if (typeof body !== "object") return res.status(400).json({ message: "Invalid body" });
|
|
79
|
+
const result = await ctx.webui.configCommandsUpdate(body, name);
|
|
80
|
+
return result ? res.sendStatus(204) : res.status(404).json({ message: "Command not found" });
|
|
81
|
+
});
|
|
89
82
|
return router;
|
|
90
83
|
};
|
package/lib/routers/api/data.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/kotori-plugin-webui
|
|
4
|
-
* @Version 1.
|
|
5
|
-
* @Author Hotaru <
|
|
4
|
+
* @Version 1.3.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/
|
|
9
|
+
* @Date 2024/8/8 20:54:17
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
13
|
-
var __create = Object.create;
|
|
14
13
|
var __defProp = Object.defineProperty;
|
|
15
14
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
15
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
18
16
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
17
|
var __export = (target, all) => {
|
|
20
18
|
for (var name in all)
|
|
@@ -28,100 +26,33 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
28
26
|
}
|
|
29
27
|
return to;
|
|
30
28
|
};
|
|
31
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
-
mod
|
|
38
|
-
));
|
|
39
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
30
|
var data_exports = {};
|
|
41
31
|
__export(data_exports, {
|
|
42
32
|
default: () => data_default
|
|
43
33
|
});
|
|
44
34
|
module.exports = __toCommonJS(data_exports);
|
|
45
|
-
var import_node_os = __toESM(require("node:os"));
|
|
46
|
-
var import_kotori_bot = require("kotori-bot");
|
|
47
|
-
var import_common = require("../../utils/common");
|
|
48
35
|
var data_default = (ctx, app) => {
|
|
49
|
-
const getModuleData = () => {
|
|
50
|
-
const list = [];
|
|
51
|
-
ctx[import_kotori_bot.Symbols.modules].forEach((module2) => list.push(module2[0].pkg));
|
|
52
|
-
return list;
|
|
53
|
-
};
|
|
54
|
-
const getBotData = () => {
|
|
55
|
-
const list = [];
|
|
56
|
-
ctx[import_kotori_bot.Symbols.bot].forEach(
|
|
57
|
-
(bot) => bot.forEach(
|
|
58
|
-
(api) => list.push({
|
|
59
|
-
status: api.adapter.status,
|
|
60
|
-
platform: api.adapter.platform,
|
|
61
|
-
identity: api.adapter.identity,
|
|
62
|
-
id: String(api.adapter.selfId),
|
|
63
|
-
lang: api.adapter.config.lang
|
|
64
|
-
})
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
return list;
|
|
68
|
-
};
|
|
69
36
|
const router = app.router();
|
|
70
37
|
router.get("/modules/:scope?/:name?", (req, res) => {
|
|
71
38
|
const { scope, name } = req.params;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const moduleData = getModuleData().find((module2) => module2.name === moduleName);
|
|
75
|
-
return moduleData ? res.json(moduleData) : res.status(404).json({ message: "Modules not found" });
|
|
39
|
+
const result = ctx.webui.dataModules(scope, name);
|
|
40
|
+
return result ? res.json(result) : res.status(404).json({ message: "Modules not found" });
|
|
76
41
|
});
|
|
77
|
-
router.get("/bots/:name", (req, res) => {
|
|
42
|
+
router.get("/bots/:name?", (req, res) => {
|
|
78
43
|
const { name } = req.params;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return botData ? res.json(botData) : res.status(404).json({ message: "Bot not found" });
|
|
44
|
+
const result = ctx.webui.dataBots(name);
|
|
45
|
+
return result ? res.json(result) : res.status(404).json({ message: "Bot not found" });
|
|
82
46
|
});
|
|
83
47
|
router.get("/stats", async (_, res) => {
|
|
84
|
-
|
|
85
|
-
const msgTotal = (0, import_common.calcGrandRecord)(ctx.webui.getMsgTotal().origin);
|
|
86
|
-
const { success: loginSuccess, failed: loginFailed } = ctx.webui.getLoginStats();
|
|
87
|
-
const chats = { received: [], sent: [] };
|
|
88
|
-
[0, 1, 2, 3, 4, 5, 6, 7].forEach((day) => {
|
|
89
|
-
const { received, sent } = (0, import_common.calcGrandRecord)(ctx.webui.getMsgDay(day).origin);
|
|
90
|
-
chats.received.push(received || 0);
|
|
91
|
-
chats.sent.push(sent || 0);
|
|
92
|
-
});
|
|
93
|
-
res.json({
|
|
94
|
-
chats,
|
|
95
|
-
count: {
|
|
96
|
-
midwares: ctx[import_kotori_bot.Symbols.midware].size,
|
|
97
|
-
commands: ctx[import_kotori_bot.Symbols.command].size,
|
|
98
|
-
regexps: ctx[import_kotori_bot.Symbols.regexp].size,
|
|
99
|
-
bots: ctx[import_kotori_bot.Symbols.bot].size,
|
|
100
|
-
adapters: ctx[import_kotori_bot.Symbols.adapter].size,
|
|
101
|
-
modules: ctx[import_kotori_bot.Symbols.modules].size
|
|
102
|
-
},
|
|
103
|
-
system: {
|
|
104
|
-
type: import_node_os.default.type(),
|
|
105
|
-
arch: import_node_os.default.arch(),
|
|
106
|
-
uptime: import_node_os.default.uptime(),
|
|
107
|
-
hostname: import_node_os.default.hostname(),
|
|
108
|
-
homedir: import_node_os.default.homedir(),
|
|
109
|
-
node: process.version
|
|
110
|
-
},
|
|
111
|
-
info: {
|
|
112
|
-
message: `${msgTotal.received}:${msgTotal.sent}`,
|
|
113
|
-
bots: `${botsStatus.filter((status) => status).length}/${botsStatus.length}`,
|
|
114
|
-
login: `${loginSuccess}:${loginFailed}`,
|
|
115
|
-
memory: `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)} MB`
|
|
116
|
-
}
|
|
117
|
-
});
|
|
48
|
+
res.json(await ctx.webui.dataStats());
|
|
118
49
|
});
|
|
119
50
|
router.get("/status", (_, res) => {
|
|
120
|
-
res.json(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
51
|
+
res.json(ctx.webui.dataStatus());
|
|
52
|
+
});
|
|
53
|
+
router.get("/avatar/:scope?/:name?", (req, res) => {
|
|
54
|
+
const { scope, name } = req.params;
|
|
55
|
+
res.type("image/svg+xml").send(ctx.webui.dataAvatar(scope, name));
|
|
125
56
|
});
|
|
126
57
|
return router;
|
|
127
58
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Context } from '
|
|
2
|
-
declare const _default: (
|
|
1
|
+
import type { Context } from 'kotori-bot';
|
|
2
|
+
declare const _default: (_: Context, app: Context['server']) => import("kotori-bot").HttpRoutes;
|
|
3
3
|
export default _default;
|
package/lib/routers/api/demo.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/kotori-plugin-webui
|
|
4
|
-
* @Version 1.
|
|
5
|
-
* @Author Hotaru <
|
|
4
|
+
* @Version 1.3.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/
|
|
9
|
+
* @Date 2024/8/8 20:54:17
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -32,7 +32,7 @@ __export(demo_exports, {
|
|
|
32
32
|
default: () => demo_default
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(demo_exports);
|
|
35
|
-
var demo_default = (
|
|
35
|
+
var demo_default = (_, app) => {
|
|
36
36
|
const router = app.router();
|
|
37
37
|
return router;
|
|
38
38
|
};
|
package/lib/routers/index.d.ts
CHANGED