node-karin 1.3.18 → 1.3.20

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # 更新日志
2
2
 
3
+ ## [1.3.20](https://github.com/KarinJS/Karin/compare/core-v1.3.19...core-v1.3.20) (2025-02-26)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * cause error ([140831f](https://github.com/KarinJS/Karin/commit/140831fe99da39506278838ca7afc3a7deca92b8))
9
+ * middleware ([8a7896e](https://github.com/KarinJS/Karin/commit/8a7896ebec77716069d9a31dc3db2da6669ca0c4))
10
+
11
+ ## [1.3.19](https://github.com/KarinJS/Karin/compare/core-v1.3.18...core-v1.3.19) (2025-02-25)
12
+
13
+
14
+ ### 🐛 Bug Fixes
15
+
16
+ * hook ([3647bb2](https://github.com/KarinJS/Karin/commit/3647bb2db51d09a7ad94c33a78abb42455300abe))
17
+
3
18
  ## [1.3.18](https://github.com/KarinJS/Karin/compare/core-v1.3.17...core-v1.3.18) (2025-02-24)
4
19
 
5
20
 
package/dist/index.d.ts CHANGED
@@ -11212,8 +11212,9 @@ interface MessageHookItem<T extends UnionMessage> {
11212
11212
  * @param contact 联系人
11213
11213
  * @param elements 消息元素
11214
11214
  * @param retryCount 重试次数
11215
+ * @param next 继续执行下一个钩子的函数
11215
11216
  */
11216
- type BaseMessageCallback<T> = (contact: Contact, elements: Array<Elements>, retryCount?: number) => T | Promise<T>;
11217
+ type BaseMessageCallback<T> = (contact: Contact, elements: Array<Elements>, retryCount: number, next: HookNext) => T | Promise<T>;
11217
11218
  /**
11218
11219
  * 接收普通消息发送回调类型 这个由开发者调用
11219
11220
  */
@@ -11227,8 +11228,9 @@ type HookEmitMessage = BaseMessageCallback<boolean>;
11227
11228
  * @param contact 联系人
11228
11229
  * @param elements 消息元素
11229
11230
  * @param options 转发选项
11231
+ * @param next 继续执行下一个钩子的函数
11230
11232
  */
11231
- type BaseForwardCallback<T> = (contact: Contact, elements: Array<NodeElement>, options?: ForwardOptions) => T | Promise<T>;
11233
+ type BaseForwardCallback<T> = (contact: Contact, elements: Array<NodeElement>, options: ForwardOptions | undefined, next: HookNext) => T | Promise<T>;
11232
11234
  /**
11233
11235
  * 接收转发消息回调类型 这个由开发者调用
11234
11236
  */
package/dist/index.js CHANGED
@@ -3043,15 +3043,14 @@ headers: ${JSON.stringify(req.headers)}
3043
3043
  body: ${JSON.stringify(req.body)}
3044
3044
  `
3045
3045
  );
3046
- if (req.path.startsWith("/api")) {
3047
- if (req.path === "/api/v1/ping" || req.path.startsWith("/api/v1/console")) {
3048
- next();
3049
- return;
3050
- }
3051
- if (!auth.getAuth(req)) {
3052
- createUnauthorizedResponse(res, "\u9519\u8BEF\u7684token");
3053
- return;
3054
- }
3046
+ if (req.path === "/ping" || req.path.startsWith("/console")) {
3047
+ next();
3048
+ return;
3049
+ }
3050
+ if (!auth.getAuth(req)) {
3051
+ createUnauthorizedResponse(res, "\u9519\u8BEF\u7684token");
3052
+ logger.error(`[express][${req.ip}] \u9274\u6743\u9519\u8BEF: /api/v1/${req.path}`);
3053
+ return;
3055
3054
  }
3056
3055
  next();
3057
3056
  };
@@ -4481,78 +4480,6 @@ var init_console = __esm({
4481
4480
  }
4482
4481
  });
4483
4482
 
4484
- // src/utils/system/restart.ts
4485
- var restart, restartDirect;
4486
- var init_restart = __esm({
4487
- "src/utils/system/restart.ts"() {
4488
- "use strict";
4489
- init_esm_shims();
4490
- init_exec();
4491
- restart = async (selfId, contact3, messageId, isFront = true) => {
4492
- const options = {
4493
- selfId,
4494
- contact: contact3,
4495
- messageId,
4496
- time: Date.now()
4497
- };
4498
- const key = `karin:restart:${selfId}`;
4499
- const { level: level2 } = await Promise.resolve().then(() => (init_index(), index_exports));
4500
- await level2.set(key, options);
4501
- if (isFront && process.send) {
4502
- process.send("restart");
4503
- return { status: "success", data: "\u5DF2\u53D1\u9001\u91CD\u542F\u4FE1\u53F7" };
4504
- }
4505
- if (process.env.PM2_RESTART === "true") process.exit();
4506
- if (process.env.pm_id) {
4507
- const { error: error2 } = await exec("npx karin rs");
4508
- if (error2) return { status: "failed", data: error2 };
4509
- process.exit();
4510
- }
4511
- const { error } = await exec("npx karin pm2");
4512
- if (error) return { status: "failed", data: error };
4513
- process.exit();
4514
- };
4515
- restartDirect = async () => {
4516
- logger.mark("\u6536\u5230\u91CD\u542F\u8BF7\u6C42\uFF0C\u6B63\u5728\u91CD\u542F...");
4517
- if (process.env.RUNTIME === "pm2") {
4518
- await exec(`pm2 restart ${process.env.pm_id}`);
4519
- return;
4520
- }
4521
- if (process.env.RUNTIME === "tsx") {
4522
- throw new Error("tsx \u4E0D\u652F\u6301\u91CD\u542F");
4523
- }
4524
- if (process == null ? void 0 : process.send) {
4525
- process.send("restart");
4526
- logger.mark("\u53D1\u9001\u91CD\u542F\u4FE1\u53F7\u6210\u529F");
4527
- }
4528
- };
4529
- }
4530
- });
4531
-
4532
- // src/server/api/manage.ts
4533
- var restartRouter, exitRouter;
4534
- var init_manage = __esm({
4535
- "src/server/api/manage.ts"() {
4536
- "use strict";
4537
- init_esm_shims();
4538
- init_router();
4539
- init_restart();
4540
- init_response();
4541
- restartRouter = async (_req, res) => {
4542
- createSuccessResponse(res, null, "\u6307\u4EE4\u53D1\u9001\u6210\u529F");
4543
- restartDirect();
4544
- };
4545
- exitRouter = async (_req, res) => {
4546
- logger.mark("\u6536\u5230\u9000\u51FA\u8BF7\u6C42\uFF0C\u6B63\u5728\u9000\u51FA...");
4547
- createSuccessResponse(res, null, "\u9000\u51FA\u6210\u529F");
4548
- const { processExit: processExit3 } = await Promise.resolve().then(() => (init_process2(), process_exports));
4549
- await processExit3(0);
4550
- };
4551
- router.post("/exit", exitRouter);
4552
- router.post("/restart", restartRouter);
4553
- }
4554
- });
4555
-
4556
4483
  // src/server/api/file/get.ts
4557
4484
  var arrayTotext, getBasicConfig, getAdapterConfig, getGroupsConfig, getPrivatesConfig, getRendersConfig, getPM2Config, getRedisConfig, getEnvConfig, getFileRouter;
4558
4485
  var init_get = __esm({
@@ -5505,28 +5432,85 @@ var init_file3 = __esm({
5505
5432
  }
5506
5433
  });
5507
5434
 
5508
- // src/server/api/login.ts
5509
- var loginRouter;
5510
- var init_login = __esm({
5511
- "src/server/api/login.ts"() {
5435
+ // src/utils/system/restart.ts
5436
+ var restart, restartDirect;
5437
+ var init_restart = __esm({
5438
+ "src/utils/system/restart.ts"() {
5439
+ "use strict";
5440
+ init_esm_shims();
5441
+ init_exec();
5442
+ restart = async (selfId, contact3, messageId, isFront = true) => {
5443
+ const options = {
5444
+ selfId,
5445
+ contact: contact3,
5446
+ messageId,
5447
+ time: Date.now()
5448
+ };
5449
+ const key = `karin:restart:${selfId}`;
5450
+ const { level: level2 } = await Promise.resolve().then(() => (init_index(), index_exports));
5451
+ await level2.set(key, options);
5452
+ if (isFront && process.send) {
5453
+ process.send("restart");
5454
+ return { status: "success", data: "\u5DF2\u53D1\u9001\u91CD\u542F\u4FE1\u53F7" };
5455
+ }
5456
+ if (process.env.PM2_RESTART === "true") process.exit();
5457
+ if (process.env.pm_id) {
5458
+ const { error: error2 } = await exec("npx karin rs");
5459
+ if (error2) return { status: "failed", data: error2 };
5460
+ process.exit();
5461
+ }
5462
+ const { error } = await exec("npx karin pm2");
5463
+ if (error) return { status: "failed", data: error };
5464
+ process.exit();
5465
+ };
5466
+ restartDirect = async () => {
5467
+ logger.mark("\u6536\u5230\u91CD\u542F\u8BF7\u6C42\uFF0C\u6B63\u5728\u91CD\u542F...");
5468
+ if (process.env.RUNTIME === "pm2") {
5469
+ await exec(`pm2 restart ${process.env.pm_id}`);
5470
+ return;
5471
+ }
5472
+ if (process.env.RUNTIME === "tsx") {
5473
+ throw new Error("tsx \u4E0D\u652F\u6301\u91CD\u542F");
5474
+ }
5475
+ if (process == null ? void 0 : process.send) {
5476
+ process.send("restart");
5477
+ logger.mark("\u53D1\u9001\u91CD\u542F\u4FE1\u53F7\u6210\u529F");
5478
+ }
5479
+ };
5480
+ }
5481
+ });
5482
+
5483
+ // src/server/api/system/manage.ts
5484
+ var restartRouter, exitRouter;
5485
+ var init_manage = __esm({
5486
+ "src/server/api/system/manage.ts"() {
5512
5487
  "use strict";
5513
5488
  init_esm_shims();
5514
- init_response();
5515
5489
  init_router();
5516
- loginRouter = async (_req, res) => {
5517
- createSuccessResponse(res, null, "\u767B\u5F55\u6210\u529F");
5490
+ init_restart();
5491
+ init_response();
5492
+ restartRouter = async (_req, res) => {
5493
+ createSuccessResponse(res, null, "\u6307\u4EE4\u53D1\u9001\u6210\u529F");
5494
+ restartDirect();
5518
5495
  };
5519
- router.post("/login", loginRouter);
5496
+ exitRouter = async (_req, res) => {
5497
+ logger.mark("\u6536\u5230\u9000\u51FA\u8BF7\u6C42\uFF0C\u6B63\u5728\u9000\u51FA...");
5498
+ createSuccessResponse(res, null, "\u9000\u51FA\u6210\u529F");
5499
+ const { processExit: processExit3 } = await Promise.resolve().then(() => (init_process2(), process_exports));
5500
+ await processExit3(0);
5501
+ };
5502
+ router.post("/exit", exitRouter);
5503
+ router.post("/restart", restartRouter);
5520
5504
  }
5521
5505
  });
5522
5506
 
5523
- // src/server/api/log.ts
5507
+ // src/server/api/system/log.ts
5524
5508
  import fs18 from "node:fs";
5525
5509
  import moment from "moment";
5526
5510
  import path12 from "node:path";
5527
5511
  var logRouter, activeConnections, getLogRouter;
5528
5512
  var init_log = __esm({
5529
- "src/server/api/log.ts"() {
5513
+ "src/server/api/system/log.ts"() {
5530
5514
  "use strict";
5531
5515
  init_esm_shims();
5532
5516
  init_root();
@@ -5596,6 +5580,32 @@ var init_log = __esm({
5596
5580
  }
5597
5581
  });
5598
5582
 
5583
+ // src/server/api/system/login.ts
5584
+ var loginRouter;
5585
+ var init_login = __esm({
5586
+ "src/server/api/system/login.ts"() {
5587
+ "use strict";
5588
+ init_esm_shims();
5589
+ init_router();
5590
+ init_response();
5591
+ loginRouter = async (_req, res) => {
5592
+ createSuccessResponse(res, null, "\u767B\u5F55\u6210\u529F");
5593
+ };
5594
+ router.post("/login", loginRouter);
5595
+ }
5596
+ });
5597
+
5598
+ // src/server/api/system/index.ts
5599
+ var init_system = __esm({
5600
+ "src/server/api/system/index.ts"() {
5601
+ "use strict";
5602
+ init_esm_shims();
5603
+ init_manage();
5604
+ init_log();
5605
+ init_login();
5606
+ }
5607
+ });
5608
+
5599
5609
  // src/utils/message/index.ts
5600
5610
  var init_message2 = __esm({
5601
5611
  "src/utils/message/index.ts"() {
@@ -5686,13 +5696,17 @@ var init_sendMsg = __esm({
5686
5696
  }
5687
5697
  };
5688
5698
  emitHooks = async (hooks2, callback) => {
5689
- const isNext = false;
5699
+ let shouldContinue = false;
5690
5700
  for (const hook of hooks2) {
5691
- const result = callback(hook);
5701
+ const next = () => {
5702
+ shouldContinue = true;
5703
+ };
5704
+ const result = callback(hook, next);
5692
5705
  if (isPromise(result)) await result;
5693
- if (!isNext) return false;
5706
+ if (!shouldContinue) return false;
5707
+ shouldContinue = false;
5694
5708
  }
5695
- return isNext;
5709
+ return true;
5696
5710
  };
5697
5711
  hooksSendMsgEmit = {
5698
5712
  /**
@@ -5702,10 +5716,10 @@ var init_sendMsg = __esm({
5702
5716
  * @param retryCount 重试次数
5703
5717
  * @returns 是否继续正常流程
5704
5718
  */
5705
- message: async (contact3, elements, retryCount) => {
5719
+ message: async (contact3, elements, retryCount = 0) => {
5706
5720
  return emitHooks(
5707
5721
  cache10.sendMsg.message,
5708
- (hook) => hook.callback(contact3, elements, retryCount)
5722
+ (hook, next) => hook.callback(contact3, elements, retryCount, next)
5709
5723
  );
5710
5724
  },
5711
5725
  /**
@@ -5718,7 +5732,7 @@ var init_sendMsg = __esm({
5718
5732
  forward: async (contact3, elements, options) => {
5719
5733
  return emitHooks(
5720
5734
  cache10.sendMsg.forward,
5721
- (hook) => hook.callback(contact3, elements, options)
5735
+ (hook, next) => hook.callback(contact3, elements, options, next)
5722
5736
  );
5723
5737
  }
5724
5738
  };
@@ -7798,8 +7812,9 @@ var init_messaeg = __esm({
7798
7812
  });
7799
7813
  if (isPromise2(result)) await result;
7800
7814
  if (!isNext) return false;
7815
+ isNext = false;
7801
7816
  }
7802
- return isNext;
7817
+ return true;
7803
7818
  };
7804
7819
  hooksMessageEmit = {
7805
7820
  /**
@@ -7931,8 +7946,16 @@ var init_groups4 = __esm({
7931
7946
  initAlias(ctx3, group.alias);
7932
7947
  initEmit(ctx3);
7933
7948
  initPrint2(ctx3, "group", "\u7FA4\u6D88\u606F", isPrint ? "info" : "debug");
7934
- hooksMessageEmit.group(ctx3);
7935
- hooksMessageEmit.message(ctx3);
7949
+ const hook = await hooksMessageEmit.group(ctx3);
7950
+ if (!hook) {
7951
+ logger.debug(`[${ctx3.logFnc}] \u7FA4\u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
7952
+ return;
7953
+ }
7954
+ const hook2 = await hooksMessageEmit.message(ctx3);
7955
+ if (!hook2) {
7956
+ logger.debug(`[${ctx3.logFnc}] \u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
7957
+ return;
7958
+ }
7936
7959
  const context2 = context(ctx3);
7937
7960
  if (context2) return ctx3;
7938
7961
  const cd = groupsCD(group, ctx3.groupId, ctx3.userId);
@@ -7960,8 +7983,16 @@ var init_groups4 = __esm({
7960
7983
  initAlias(ctx3, group.alias);
7961
7984
  initEmit(ctx3);
7962
7985
  initPrint2(ctx3, "groupTemp", "\u7FA4\u4E34\u65F6\u6D88\u606F");
7963
- hooksMessageEmit.groupTemp(ctx3);
7964
- hooksMessageEmit.message(ctx3);
7986
+ const hook = await hooksMessageEmit.groupTemp(ctx3);
7987
+ if (!hook) {
7988
+ logger.debug(`[${ctx3.logFnc}] \u7FA4\u4E34\u65F6\u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
7989
+ return;
7990
+ }
7991
+ const hook2 = await hooksMessageEmit.message(ctx3);
7992
+ if (!hook2) {
7993
+ logger.debug(`[${ctx3.logFnc}] \u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
7994
+ return;
7995
+ }
7965
7996
  const context2 = context(ctx3);
7966
7997
  if (context2) return ctx3;
7967
7998
  const cd = groupsCD(group, ctx3.groupId, ctx3.userId);
@@ -8091,8 +8122,16 @@ var init_private3 = __esm({
8091
8122
  initAlias(ctx3, friend.alias);
8092
8123
  initEmit(ctx3);
8093
8124
  initPrint3(ctx3, "friend", "\u597D\u53CB\u6D88\u606F");
8094
- hooksMessageEmit.friend(ctx3);
8095
- hooksMessageEmit.message(ctx3);
8125
+ const hook = await hooksMessageEmit.friend(ctx3);
8126
+ if (!hook) {
8127
+ logger.debug(`[${ctx3.logFnc}] \u597D\u53CB\u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
8128
+ return;
8129
+ }
8130
+ const hook2 = await hooksMessageEmit.message(ctx3);
8131
+ if (!hook2) {
8132
+ logger.debug(`[${ctx3.logFnc}] \u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
8133
+ return;
8134
+ }
8096
8135
  const context2 = context(ctx3);
8097
8136
  if (context2) return ctx3;
8098
8137
  const filter = privateFilterEvent(ctx3, config2, friend, privateCD(friend, ctx3.userId));
@@ -8112,8 +8151,16 @@ var init_private3 = __esm({
8112
8151
  initAlias(ctx3, friend.alias);
8113
8152
  initEmit(ctx3);
8114
8153
  initPrint3(ctx3, "direct", "\u9891\u9053\u79C1\u4FE1");
8115
- hooksMessageEmit.direct(ctx3);
8116
- hooksMessageEmit.message(ctx3);
8154
+ const hook = await hooksMessageEmit.direct(ctx3);
8155
+ if (!hook) {
8156
+ logger.debug(`[${ctx3.logFnc}] \u9891\u9053\u79C1\u4FE1\u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
8157
+ return;
8158
+ }
8159
+ const hook2 = await hooksMessageEmit.message(ctx3);
8160
+ if (!hook2) {
8161
+ logger.debug(`[${ctx3.logFnc}] \u6D88\u606F\u94A9\u5B50\u8FD4\u56DEfalse \u8DF3\u8FC7\u5F53\u524D\u4E8B\u4EF6: ${ctx3.eventId}`);
8162
+ return;
8163
+ }
8117
8164
  const context2 = context(ctx3);
8118
8165
  if (context2) return ctx3;
8119
8166
  const cd = privateCD(friend, ctx3.userId);
@@ -11855,10 +11902,8 @@ var init_api = __esm({
11855
11902
  init_info();
11856
11903
  init_root2();
11857
11904
  init_console();
11858
- init_manage();
11859
11905
  init_file3();
11860
- init_login();
11861
- init_log();
11906
+ init_system();
11862
11907
  init_sandbox();
11863
11908
  init_plugins();
11864
11909
  }
@@ -16236,7 +16281,7 @@ var init_button = __esm({
16236
16281
  import os3 from "node:os";
16237
16282
  import fs29 from "node:fs";
16238
16283
  var isWin2, isLinux, isMac, isDocker, isRoot;
16239
- var init_system = __esm({
16284
+ var init_system2 = __esm({
16240
16285
  "src/utils/system/system.ts"() {
16241
16286
  "use strict";
16242
16287
  init_esm_shims();
@@ -16255,7 +16300,7 @@ var init_pid = __esm({
16255
16300
  "use strict";
16256
16301
  init_esm_shims();
16257
16302
  init_exec();
16258
- init_system();
16303
+ init_system2();
16259
16304
  getPid = async (port2) => {
16260
16305
  const command2 = isWin2 ? `netstat -ano | findstr :${port2}` : `lsof -i:${port2} | grep LISTEN | awk '{print $2}'`;
16261
16306
  const { stdout } = await exec(command2);
@@ -16374,7 +16419,7 @@ __export(system_exports, {
16374
16419
  updatePkg: () => updatePkg,
16375
16420
  uptime: () => uptime2
16376
16421
  });
16377
- var init_system2 = __esm({
16422
+ var init_system3 = __esm({
16378
16423
  "src/utils/system/index.ts"() {
16379
16424
  "use strict";
16380
16425
  init_esm_shims();
@@ -16386,7 +16431,7 @@ var init_system2 = __esm({
16386
16431
  init_error();
16387
16432
  init_ffmpeg();
16388
16433
  init_import();
16389
- init_system();
16434
+ init_system2();
16390
16435
  init_update();
16391
16436
  init_restart();
16392
16437
  init_fileToUrl();
@@ -16401,10 +16446,10 @@ var init_utils = __esm({
16401
16446
  init_button();
16402
16447
  init_fs2();
16403
16448
  init_logger();
16404
- init_system2();
16449
+ init_system3();
16405
16450
  init_message2();
16406
16451
  init_fs2();
16407
- init_system2();
16452
+ init_system3();
16408
16453
  init_common();
16409
16454
  init_config2();
16410
16455
  init_changelog();
@@ -16527,7 +16572,7 @@ var init_client2 = __esm({
16527
16572
  this.registerBot();
16528
16573
  } catch (error) {
16529
16574
  this.socket.close();
16530
- throw new Error(`[onebot11][${this.adapter.communication}] \u8FDE\u63A5\u5931\u8D25: ${this.adapter.address}`);
16575
+ throw new Error(`[onebot11][${this.adapter.communication}] \u8FDE\u63A5\u5931\u8D25: ${this.adapter.address}`, { cause: error });
16531
16576
  }
16532
16577
  }
16533
16578
  };
@@ -16602,7 +16647,7 @@ var init_server2 = __esm({
16602
16647
  });
16603
16648
  } catch (error) {
16604
16649
  this.socket.close();
16605
- throw new Error(`[onebot11][${this.adapter.communication}] \u8FDE\u63A5\u5931\u8D25: ${this.adapter.address}`);
16650
+ throw new Error(`[onebot11][${this.adapter.communication}] \u8FDE\u63A5\u5931\u8D25: ${this.adapter.address}`, { cause: error });
16606
16651
  }
16607
16652
  }
16608
16653
  /**
@@ -0,0 +1 @@
1
+ import{d as a}from"./index-Wy6xtsbt.js";var r=a;export{r as default};