koishi-plugin-best-cave 1.5.7 → 1.5.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.
Files changed (2) hide show
  1. package/lib/index.js +14 -9
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -99,7 +99,7 @@ var FileHandler = class {
99
99
  return await operation();
100
100
  } catch (error) {
101
101
  if (i === this.RETRY_COUNT - 1) throw error;
102
- await new Promise((resolve2) => setTimeout(resolve2, this.RETRY_DELAY));
102
+ await new Promise((resolve) => setTimeout(resolve, this.RETRY_DELAY));
103
103
  }
104
104
  }
105
105
  throw new Error("Operation failed after retries");
@@ -1182,8 +1182,6 @@ ${session.text("commands.cave.audit.from")}${cave.contributor_number}`;
1182
1182
  var import_koishi5 = require("koishi");
1183
1183
  var fs5 = __toESM(require("fs"));
1184
1184
  var path5 = __toESM(require("path"));
1185
- var import_url = require("url");
1186
- var import_path = require("path");
1187
1185
  var logger4 = new import_koishi5.Logger("MediaHandle");
1188
1186
  async function buildMessage(cave, resourceDir, session) {
1189
1187
  if (!cave?.elements?.length) {
@@ -1209,9 +1207,8 @@ async function buildMessage(cave, resourceDir, session) {
1209
1207
  if (element.type === "text") {
1210
1208
  lines.push(element.content);
1211
1209
  } else if (element.type === "img" && element.file) {
1212
- const filePath = (0, import_path.resolve)(resourceDir, element.file);
1213
- const fileUrl = (0, import_url.pathToFileURL)(filePath);
1214
- lines.push((0, import_koishi5.h)("image", { src: fileUrl.toString() }));
1210
+ const filePath = path5.join(resourceDir, element.file);
1211
+ lines.push(import_koishi5.h.image(filePath));
1215
1212
  }
1216
1213
  }
1217
1214
  lines.push(session.text("commands.cave.message.contributorSuffix", [cave.contributor_name]));
@@ -1237,9 +1234,17 @@ async function sendMessage(session, key, params = [], isTemp = true, timeout = 1
1237
1234
  }
1238
1235
  __name(sendMessage, "sendMessage");
1239
1236
  async function processMediaFile(filePath, type) {
1240
- const data = await fs5.promises.readFile(filePath).catch(() => null);
1241
- if (!data) return null;
1242
- return `data:${type}/${type === "image" ? "png" : "mp4"};base64,${data.toString("base64")}`;
1237
+ try {
1238
+ await fs5.promises.access(filePath);
1239
+ if (type === "image") {
1240
+ return filePath;
1241
+ } else {
1242
+ const data = await fs5.promises.readFile(filePath);
1243
+ return `data:${type}/mp4;base64,${data.toString("base64")}`;
1244
+ }
1245
+ } catch {
1246
+ return null;
1247
+ }
1243
1248
  }
1244
1249
  __name(processMediaFile, "processMediaFile");
1245
1250
  async function extractMediaContent(originalContent, config, session) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "最好的 cave 插件,可开关的审核系统,可引用添加,支持图文混合内容,可查阅投稿列表,完美复刻你的 .cave 体验!",
4
- "version": "1.5.7",
4
+ "version": "1.5.9",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],