@karinjs/plugin-basic 1.0.9 → 1.1.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 CHANGED
@@ -20,4 +20,8 @@ pnpm add @karinjs/plugin-basic -w
20
20
 
21
21
  ```
22
22
  # 插件列表
23
- ```
23
+ ```
24
+
25
+ ```
26
+ #web登录
27
+ ```
@@ -2,5 +2,6 @@
2
2
  "status": true,
3
3
  "forward": true,
4
4
  "restartMode": true,
5
- "restart": true
5
+ "restart": true,
6
+ "domain": ""
6
7
  }
@@ -0,0 +1,5 @@
1
+ import * as node_karin from 'node-karin';
2
+
3
+ declare const login: node_karin.Command<keyof node_karin.MessageEventMap>;
4
+
5
+ export { login };
@@ -0,0 +1,70 @@
1
+ import {
2
+ config
3
+ } from "../chunk-DYA7JXHS.js";
4
+ import "../chunk-CUYZ6VZG.js";
5
+
6
+ // src/apps/login.ts
7
+ import karin, { common, contactFriend, logger, segment } from "node-karin";
8
+ import axios from "node-karin/axios";
9
+ import os from "os";
10
+ var url = { IPv4: ["https://4.ipw.cn"], IPv6: ["https://6.ipw.cn"] };
11
+ var login = karin.command(/#?(面板|web)登录$/i, async (e) => {
12
+ const net = os.networkInterfaces();
13
+ const cfg = config();
14
+ const IP = { lan: { ipv4: null, ipv6: null }, net: { ipv4: null, ipv6: null } };
15
+ for (const i in net) {
16
+ for (const iface of net[i]) {
17
+ if (iface.internal) continue;
18
+ if (iface.family === "IPv4") {
19
+ const ip = iface.address;
20
+ if (ip.startsWith("192.168.") || ip.startsWith("10.") || ip.startsWith("172.") && parseInt(ip.split(".")[1]) >= 16 && parseInt(ip.split(".")[1]) <= 31) {
21
+ IP.lan.ipv4 = ip;
22
+ }
23
+ } else if (iface.family === "IPv6") {
24
+ const ip = iface.address;
25
+ if (ip.startsWith("fd") || ip.startsWith("fe80:") || ip.startsWith("fc")) {
26
+ IP.lan.ipv6 = ip;
27
+ }
28
+ }
29
+ }
30
+ }
31
+ IP.net.ipv4 = await getnetIP("IPv4");
32
+ IP.net.ipv6 = await getnetIP("IPv6");
33
+ const port = process.env.HTTP_PORT;
34
+ const token = process.env.HTTP_AUTH_KEY;
35
+ const msg = [segment.text("\u9762\u677F\u767B\u5F55\u5730\u5740\uFF1A")];
36
+ if (cfg.domain) msg.push(segment.text(`- \u81EA\u5B9A\u4E49\u57DF\u540D: ${cfg.domain}/web/login?token=${token}`));
37
+ msg.push(segment.text(`- \u5185\u7F51\u5730\u5740: ${IP.lan.ipv4 ? `http://${IP.lan.ipv4}:${port}/web/login?token=${token}` : `http://${IP.lan.ipv4}:${port}/web/login?token=${token}`}`));
38
+ if (IP.net.ipv4) msg.push(segment.text(`- \u5916\u7F51IPv4\u5730\u5740: http://${IP.net.ipv4}:${port}/web/login?token=${token}`));
39
+ if (IP.net.ipv6) msg.push(segment.text(`- \u5916\u7F51IPv6\u5730\u5740: http://${IP.net.ipv6}:${port}/web/login?token=${token}`));
40
+ try {
41
+ const content = common.makeForward(msg, e.selfId, e.bot.account.name);
42
+ await e.bot.sendForwardMsg(contactFriend(e.userId), content);
43
+ if (e.isGroup) await e.reply("\u767B\u5F55\u5730\u5740\u5DF2\u7ECF\u79C1\u4FE1\u7ED9\u4E3B\u4EBA\u4E86\u54E6~");
44
+ } catch (err) {
45
+ msg.forEach((item) => {
46
+ item.text = item.text + "\n";
47
+ });
48
+ await e.bot.sendMsg(contactFriend(e.userId), msg);
49
+ if (e.isGroup) await e.reply("\u767B\u5F55\u5730\u5740\u5DF2\u7ECF\u79C1\u4FE1\u7ED9\u4E3B\u4EBA\u4E86\u54E6~");
50
+ return true;
51
+ }
52
+ return true;
53
+ }, { name: "\u9762\u677F\u767B\u5F55", perm: "admin" });
54
+ async function getnetIP(type) {
55
+ for (const i of url[type] || []) {
56
+ try {
57
+ const res = await axios.get(i);
58
+ if (res.data) {
59
+ return res.data;
60
+ }
61
+ } catch (e) {
62
+ logger.error(`\u8BBF\u95EE${i}\u83B7\u53D6\u5916\u7F51${type}\u5730\u5740\u5931\u8D25: ${e}`);
63
+ continue;
64
+ }
65
+ }
66
+ return null;
67
+ }
68
+ export {
69
+ login
70
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  config
3
- } from "../chunk-IN6XLNTH.js";
4
- import "../chunk-473NAVE6.js";
3
+ } from "../chunk-DYA7JXHS.js";
4
+ import "../chunk-CUYZ6VZG.js";
5
5
 
6
6
  // src/apps/restart.ts
7
7
  import { common, karin, logger, restart } from "node-karin";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  config
3
- } from "../chunk-IN6XLNTH.js";
4
- import "../chunk-473NAVE6.js";
3
+ } from "../chunk-DYA7JXHS.js";
4
+ import "../chunk-CUYZ6VZG.js";
5
5
 
6
6
  // src/apps/status.ts
7
7
  import moment from "node-karin/moment";
@@ -1,6 +1,6 @@
1
1
  // src/apps/update.ts
2
- import fs from "node:fs";
3
- import path from "node:path";
2
+ import fs from "fs";
3
+ import path from "path";
4
4
  import { changelog, checkGitPluginUpdate, checkPkgUpdate, getCommit, getPlugins, getPkgVersion, karin, updateAllGitPlugin, updateAllPkg, updateGitPlugin, updatePkg } from "node-karin";
5
5
  var cache = [];
6
6
  var getAll = async () => {
@@ -1,10 +1,10 @@
1
1
  // src/root.ts
2
- import path from "node:path";
2
+ import path from "path";
3
3
 
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@karinjs/plugin-basic",
7
- version: "1.0.9",
7
+ version: "1.1.0",
8
8
  description: "karin plugin for basic functions",
9
9
  homepage: "https://github.com/KarinJS/karin-plugin-basic",
10
10
  bugs: {
@@ -34,12 +34,12 @@ var package_default = {
34
34
  karin: "karin"
35
35
  },
36
36
  devDependencies: {
37
- "@types/node": "^20.17.30",
38
- eslint: "^9.24.0",
37
+ "@types/node": "^24.0.1",
38
+ eslint: "^9.29.0",
39
39
  neostandard: "^0.12.1",
40
- "node-karin": "^1.8.12",
41
- tsup: "^8.4.0",
42
- tsx: "^4.19.3",
40
+ "node-karin": "^1.10.7",
41
+ tsup: "^8.5.0",
42
+ tsx: "^4.20.3",
43
43
  typescript: "^5.8.3"
44
44
  },
45
45
  publishConfig: {
@@ -62,11 +62,14 @@ var package_default = {
62
62
  ],
63
63
  "ts-web": "src/web.config.ts",
64
64
  web: "dist/web.config.js"
65
+ },
66
+ dependencies: {
67
+ "internal-ip": "^8.0.0"
65
68
  }
66
69
  };
67
70
 
68
71
  // src/root.ts
69
- import { fileURLToPath } from "node:url";
72
+ import { fileURLToPath } from "url";
70
73
  var __filename = fileURLToPath(import.meta.url);
71
74
  var __dirname = path.dirname(__filename);
72
75
  var __pluginDir = path.resolve(__dirname, "../");
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  info
3
- } from "./chunk-473NAVE6.js";
3
+ } from "./chunk-CUYZ6VZG.js";
4
4
 
5
5
  // src/utils/config.ts
6
- import fs from "node:fs";
7
- import path from "node:path";
6
+ import fs from "fs";
7
+ import path from "path";
8
8
  import {
9
9
  watch,
10
10
  basePath,
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  info
3
- } from "./chunk-473NAVE6.js";
3
+ } from "./chunk-CUYZ6VZG.js";
4
4
 
5
5
  // src/index.ts
6
6
  import { logger } from "node-karin";
@@ -10,6 +10,8 @@ interface Config {
10
10
  restartMode: boolean;
11
11
  /** 更新完成是否自动重启 */
12
12
  restart: boolean;
13
+ /** 自定义登录域名 */
14
+ domain: string;
13
15
  }
14
16
 
15
17
  declare const _default: {
@@ -23,7 +25,7 @@ declare const _default: {
23
25
  }[];
24
26
  };
25
27
  /** 动态渲染的组件 */
26
- components: () => node_karin.SwitchProps[];
28
+ components: () => (node_karin.SwitchProps | node_karin.InputProps)[];
27
29
  /** 前端点击保存之后调用的方法 */
28
30
  save: (config: Config) => {
29
31
  success: boolean;
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  config,
3
3
  writeConfig
4
- } from "./chunk-IN6XLNTH.js";
4
+ } from "./chunk-DYA7JXHS.js";
5
5
  import {
6
6
  info
7
- } from "./chunk-473NAVE6.js";
7
+ } from "./chunk-CUYZ6VZG.js";
8
8
 
9
9
  // src/web.config.ts
10
10
  import { components } from "node-karin";
@@ -47,6 +47,13 @@ var web_config_default = {
47
47
  label: "\u81EA\u52A8\u91CD\u542F",
48
48
  description: "\u66F4\u65B0\u5B8C\u6210\u662F\u5426\u81EA\u52A8\u91CD\u542F",
49
49
  defaultSelected: cfg.restart
50
+ }),
51
+ components.input.string("domain", {
52
+ color: "success",
53
+ label: "\u81EA\u5B9A\u4E49\u57DF\u540D",
54
+ description: "Web\u767B\u5F55\u53D1\u9001\u7684\u81EA\u5B9A\u4E49\u57DF\u540D",
55
+ defaultValue: cfg.domain,
56
+ isRequired: false
50
57
  })
51
58
  ];
52
59
  return list;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karinjs/plugin-basic",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "karin plugin for basic functions",
5
5
  "homepage": "https://github.com/KarinJS/karin-plugin-basic",
6
6
  "bugs": {
@@ -49,5 +49,8 @@
49
49
  ],
50
50
  "ts-web": "src/web.config.ts",
51
51
  "web": "dist/web.config.js"
52
+ },
53
+ "dependencies": {
54
+ "internal-ip": "^8.0.0"
52
55
  }
53
56
  }