koishi-plugin-starfx-bot 0.19.6 → 0.19.8

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/lib/index.js CHANGED
@@ -970,7 +970,7 @@ var package_default = {
970
970
  contributors: [
971
971
  "StarFreedomX <starfreedomx@outlook.com>"
972
972
  ],
973
- version: "0.19.6",
973
+ version: "0.19.8",
974
974
  main: "lib/index.js",
975
975
  typings: "lib/index.d.ts",
976
976
  files: [
@@ -1293,13 +1293,19 @@ function apply(ctx, cfg) {
1293
1293
  }
1294
1294
  if (cfg.filePathToBase64) {
1295
1295
  let isLocalPath = function(src) {
1296
- return /^([A-Za-z]:\\|\\\\|\/home\/|\/root\/)/.test(src);
1296
+ const LOCAL_PATH_REGEX = /^(\/|\\|file:\/\/\/|\.|[A-Za-z]:\\|\/home\/|\/root\/|\.\.\/|\.\/)/;
1297
+ return LOCAL_PATH_REGEX.test(src);
1298
+ }, convertUriToLocalPath = function(uri) {
1299
+ if (uri.startsWith("file:///")) {
1300
+ return decodeURIComponent(uri.substring(7));
1301
+ }
1302
+ return uri;
1297
1303
  }, toBase64String = function(src) {
1298
1304
  try {
1299
1305
  const data = fs2.readFileSync(src);
1300
1306
  return data.toString("base64");
1301
1307
  } catch (err) {
1302
- console.error(err);
1308
+ starfxLogger.error(`[Error] 无法读取本地文件 (${src}) 并转换为 Base64:`, err);
1303
1309
  return void 0;
1304
1310
  }
1305
1311
  }, guessTypeFromElement = function(type) {
@@ -1316,14 +1322,16 @@ function apply(ctx, cfg) {
1316
1322
  }
1317
1323
  };
1318
1324
  __name(isLocalPath, "isLocalPath");
1325
+ __name(convertUriToLocalPath, "convertUriToLocalPath");
1319
1326
  __name(toBase64String, "toBase64String");
1320
1327
  __name(guessTypeFromElement, "guessTypeFromElement");
1321
1328
  ctx.before("send", (session, options) => {
1322
1329
  for (const element of session.elements) {
1323
1330
  const src = element.attrs?.src;
1324
1331
  if (!src || !isLocalPath(src)) continue;
1325
- const mimeType = import_mime_types.default.lookup(src) || guessTypeFromElement(element.type) || "application/octet-stream";
1326
- const base64 = toBase64String(src);
1332
+ const filePath = convertUriToLocalPath(src);
1333
+ const mimeType = import_mime_types.default.lookup(filePath) || guessTypeFromElement(element.type) || "application/octet-stream";
1334
+ const base64 = toBase64String(filePath);
1327
1335
  if (base64) element.attrs.src = `data:${mimeType};base64,${base64}`;
1328
1336
  }
1329
1337
  });
@@ -1342,11 +1350,11 @@ function apply(ctx, cfg) {
1342
1350
  }
1343
1351
  }
1344
1352
  }
1345
- if (detectControl(controlJson, session.guildId, "atNotSay"))
1353
+ if (cfg.atNotSay && detectControl(controlJson, session.guildId, "atNotSay"))
1346
1354
  await atNotSayReply(cfg, session, elements);
1347
- if (detectControl(controlJson, session.guildId, "replyBot"))
1355
+ if (cfg.replyBot && detectControl(controlJson, session.guildId, "replyBot"))
1348
1356
  await replyBot(cfg, session, elements);
1349
- if (detectControl(controlJson, session.guildId, "iLoveYou"))
1357
+ if (cfg.iLoveYou && detectControl(controlJson, session.guildId, "iLoveYou"))
1350
1358
  await iLoveYou(cfg, session, elements);
1351
1359
  return next();
1352
1360
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.19.6",
7
+ "version": "0.19.8",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
package/readme.md CHANGED
@@ -118,3 +118,5 @@ StarFreedomX机器人的小功能,自用
118
118
  | `0.19.4` | inject database for ctx.broadcast |
119
119
  | `0.19.5` | 提取代码量较大的功能为单独插件 |
120
120
  | `0.19.6` | 查汇率支持近5d |
121
+ | `0.19.7` | base64转换捕获file协议 |
122
+ | `0.19.8` | base64适配linux目录 |