koishi-plugin-echo-cave 1.12.2 → 1.13.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 +12 -4
- package/lib/index.d.ts +1 -0
- package/lib/media-helper.d.ts +2 -2
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -40,7 +40,8 @@ var require_zh_CN = __commonJS({
|
|
|
40
40
|
enableSizeLimit: "\u662F\u5426\u542F\u7528\u5A92\u4F53\u6587\u4EF6\u5927\u5C0F\u9650\u5236",
|
|
41
41
|
maxImageSize: "\u6700\u5927\u56FE\u7247\u5927\u5C0F (MB)",
|
|
42
42
|
maxVideoSize: "\u6700\u5927\u89C6\u9891\u5927\u5C0F (MB)",
|
|
43
|
-
maxFileSize: "\u6700\u5927\u6587\u4EF6\u5927\u5C0F (MB)"
|
|
43
|
+
maxFileSize: "\u6700\u5927\u6587\u4EF6\u5927\u5C0F (MB)",
|
|
44
|
+
maxRecordSize: "\u6700\u5927\u5F55\u97F3\u5927\u5C0F (MB)"
|
|
44
45
|
},
|
|
45
46
|
"echo-cave": {
|
|
46
47
|
general: {
|
|
@@ -228,7 +229,7 @@ async function saveMedia(ctx, mediaElement, type, cfg) {
|
|
|
228
229
|
const originalMediaName = mediaElement.file;
|
|
229
230
|
const ext = (() => {
|
|
230
231
|
const i = originalMediaName.lastIndexOf(".");
|
|
231
|
-
return i === -1 ? type === "image" ? "png" : type === "video" ? "mp4" : "bin" : originalMediaName.slice(i + 1).toLowerCase();
|
|
232
|
+
return i === -1 ? type === "image" ? "png" : type === "video" ? "mp4" : type === "record" ? "mp3" : "bin" : originalMediaName.slice(i + 1).toLowerCase();
|
|
232
233
|
})();
|
|
233
234
|
const mediaDir = import_node_path.default.join(ctx.baseDir, "data", "cave", type + "s");
|
|
234
235
|
const mediaName = Date.now().toString();
|
|
@@ -256,6 +257,10 @@ async function saveMedia(ctx, mediaElement, type, cfg) {
|
|
|
256
257
|
ctx.logger.warn(`Invalid video content-type: ${contentType}`);
|
|
257
258
|
return mediaUrl;
|
|
258
259
|
}
|
|
260
|
+
if (type === "record" && !contentType.startsWith("audio/")) {
|
|
261
|
+
ctx.logger.warn(`Invalid record content-type: ${contentType}`);
|
|
262
|
+
return mediaUrl;
|
|
263
|
+
}
|
|
259
264
|
}
|
|
260
265
|
const buffer = Buffer.from(res.data);
|
|
261
266
|
if (!buffer || buffer.length === 0) {
|
|
@@ -274,7 +279,7 @@ async function saveMedia(ctx, mediaElement, type, cfg) {
|
|
|
274
279
|
}
|
|
275
280
|
}
|
|
276
281
|
async function processMediaElement(ctx, element, cfg) {
|
|
277
|
-
if (element.type === "image" || element.type === "video" || element.type === "file") {
|
|
282
|
+
if (element.type === "image" || element.type === "video" || element.type === "file" || element.type === "record") {
|
|
278
283
|
const savedPath = await saveMedia(
|
|
279
284
|
ctx,
|
|
280
285
|
element.data,
|
|
@@ -308,6 +313,8 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
|
|
|
308
313
|
return (cfg.maxVideoSize || 500) * 1024 * 1024;
|
|
309
314
|
case "file":
|
|
310
315
|
return (cfg.maxFileSize || 1e3) * 1024 * 1024;
|
|
316
|
+
case "record":
|
|
317
|
+
return (cfg.maxRecordSize || 200) * 1024 * 1024;
|
|
311
318
|
}
|
|
312
319
|
})();
|
|
313
320
|
try {
|
|
@@ -425,7 +432,8 @@ var Config = import_koishi.Schema.object({
|
|
|
425
432
|
enableSizeLimit: import_koishi.Schema.boolean().default(false),
|
|
426
433
|
maxImageSize: import_koishi.Schema.number().default(2048),
|
|
427
434
|
maxVideoSize: import_koishi.Schema.number().default(512),
|
|
428
|
-
maxFileSize: import_koishi.Schema.number().default(512)
|
|
435
|
+
maxFileSize: import_koishi.Schema.number().default(512),
|
|
436
|
+
maxRecordSize: import_koishi.Schema.number().default(512)
|
|
429
437
|
}).i18n({
|
|
430
438
|
"zh-CN": require_zh_CN()._config
|
|
431
439
|
});
|
package/lib/index.d.ts
CHANGED
package/lib/media-helper.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Config } from './index';
|
|
2
2
|
import { Context } from 'koishi';
|
|
3
|
-
export declare function saveMedia(ctx: Context, mediaElement: Record<string, any>, type: 'image' | 'video' | 'file', cfg: Config): Promise<string>;
|
|
3
|
+
export declare function saveMedia(ctx: Context, mediaElement: Record<string, any>, type: 'image' | 'video' | 'file' | 'record', cfg: Config): Promise<string>;
|
|
4
4
|
export declare function processMediaElement(ctx: Context, element: any, cfg: Config): Promise<any>;
|
|
5
|
-
export declare function checkAndCleanMediaFiles(ctx: Context, cfg: Config, type: 'image' | 'video' | 'file'): Promise<void>;
|
|
5
|
+
export declare function checkAndCleanMediaFiles(ctx: Context, cfg: Config, type: 'image' | 'video' | 'file' | 'record'): Promise<void>;
|