koishi-plugin-echo-cave 1.13.0 → 1.14.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/lib/index.cjs CHANGED
@@ -41,7 +41,8 @@ var require_zh_CN = __commonJS({
41
41
  maxImageSize: "\u6700\u5927\u56FE\u7247\u5927\u5C0F (MB)",
42
42
  maxVideoSize: "\u6700\u5927\u89C6\u9891\u5927\u5C0F (MB)",
43
43
  maxFileSize: "\u6700\u5927\u6587\u4EF6\u5927\u5C0F (MB)",
44
- maxRecordSize: "\u6700\u5927\u5F55\u97F3\u5927\u5C0F (MB)"
44
+ maxRecordSize: "\u6700\u5927\u5F55\u97F3\u5927\u5C0F (MB)",
45
+ useBase64ForMedia: "\u662F\u5426\u4F7F\u7528Base64\u7F16\u7801\u4FDD\u5B58\u5A92\u4F53\u6587\u4EF6\uFF0C\u5F00\u542F\u540E\u5C06\u76F4\u63A5\u5B58\u50A8\u6587\u4EF6\u5185\u5BB9\u800C\u975E\u6587\u4EF6\u8DEF\u5F84"
45
46
  },
46
47
  "echo-cave": {
47
48
  general: {
@@ -286,12 +287,27 @@ async function processMediaElement(ctx, element, cfg) {
286
287
  element.type,
287
288
  cfg
288
289
  );
289
- const fileUri = `file:///${savedPath.replace(/\\/g, "/")}`;
290
+ let fileValue;
291
+ if (cfg.useBase64ForMedia) {
292
+ const buffer = await import_node_fs.promises.readFile(savedPath);
293
+ const base64 = buffer.toString("base64");
294
+ const mimeTypes = {
295
+ image: "image/jpeg",
296
+ video: "video/mp4",
297
+ record: "audio/mpeg",
298
+ file: "application/octet-stream"
299
+ };
300
+ const mimeType = mimeTypes[element.type] || "application/octet-stream";
301
+ fileValue = `data:${mimeType};base64,${base64}`;
302
+ } else {
303
+ const fileUri = `file:///${savedPath.replace(/\\/g, "/")}`;
304
+ fileValue = fileUri;
305
+ }
290
306
  return {
291
307
  ...element,
292
308
  data: {
293
309
  ...element.data,
294
- file: fileUri,
310
+ file: fileValue,
295
311
  // Remove the url field
296
312
  url: void 0
297
313
  }
@@ -433,7 +449,8 @@ var Config = import_koishi.Schema.object({
433
449
  maxImageSize: import_koishi.Schema.number().default(2048),
434
450
  maxVideoSize: import_koishi.Schema.number().default(512),
435
451
  maxFileSize: import_koishi.Schema.number().default(512),
436
- maxRecordSize: import_koishi.Schema.number().default(512)
452
+ maxRecordSize: import_koishi.Schema.number().default(512),
453
+ useBase64ForMedia: import_koishi.Schema.boolean().default(false)
437
454
  }).i18n({
438
455
  "zh-CN": require_zh_CN()._config
439
456
  });
package/lib/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export interface Config {
11
11
  maxVideoSize?: number;
12
12
  maxFileSize?: number;
13
13
  maxRecordSize?: number;
14
+ useBase64ForMedia?: boolean;
14
15
  }
15
16
  export declare const Config: Schema<Config>;
16
17
  export interface EchoCave {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.13.0",
4
+ "version": "1.14.0",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",