@meet-im/meet 1.1.0 → 1.1.1

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/package.json +1 -1
  2. package/src/send.ts +64 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meet-im/meet",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Meet channel plugin",
6
6
  "scripts": {
package/src/send.ts CHANGED
@@ -8,6 +8,67 @@ import { getMeetRuntime } from "./runtime.js";
8
8
 
9
9
  const MENTION_PATTERN = /<@(-?\d+)>|@(-?\d+)(?![\d])/g;
10
10
 
11
+ /**
12
+ * 根据文件扩展名推断 MIME 类型
13
+ * 支持常见图片格式,包括现代格式如 avif, webp, heic
14
+ */
15
+ export function inferContentTypeFromFileName(fileName: string): string | undefined {
16
+ const ext = fileName.toLowerCase().split(".").pop();
17
+ if (!ext) return undefined;
18
+
19
+ const mimeMap: Record<string, string> = {
20
+ // 常见图片格式
21
+ jpg: "image/jpeg",
22
+ jpeg: "image/jpeg",
23
+ png: "image/png",
24
+ gif: "image/gif",
25
+ webp: "image/webp",
26
+ avif: "image/avif",
27
+ heic: "image/heic",
28
+ heif: "image/heif",
29
+ bmp: "image/bmp",
30
+ ico: "image/x-icon",
31
+ svg: "image/svg+xml",
32
+ tiff: "image/tiff",
33
+ tif: "image/tiff",
34
+ // 视频格式
35
+ mp4: "video/mp4",
36
+ webm: "video/webm",
37
+ mov: "video/quicktime",
38
+ avi: "video/x-msvideo",
39
+ mkv: "video/x-matroska",
40
+ // 音频格式
41
+ mp3: "audio/mpeg",
42
+ wav: "audio/wav",
43
+ ogg: "audio/ogg",
44
+ flac: "audio/flac",
45
+ m4a: "audio/mp4",
46
+ // 文档格式
47
+ pdf: "application/pdf",
48
+ json: "application/json",
49
+ xml: "application/xml",
50
+ };
51
+
52
+ return mimeMap[ext];
53
+ }
54
+
55
+ /**
56
+ * 获取最终的 contentType
57
+ * 如果原始 contentType 缺失或为通用二进制流,则根据文件名推断
58
+ */
59
+ export function resolveContentType(
60
+ fileName: string,
61
+ originalContentType?: string,
62
+ ): string {
63
+ // 如果有明确的 MIME 类型(非通用二进制流),直接使用
64
+ if (originalContentType && originalContentType !== "application/octet-stream") {
65
+ return originalContentType;
66
+ }
67
+ // 根据文件名推断
68
+ const inferred = inferContentTypeFromFileName(fileName);
69
+ return inferred || originalContentType || "application/octet-stream";
70
+ }
71
+
11
72
  let _logger: RuntimeEnv | null = null;
12
73
 
13
74
  export function setSendMessageLogger(logger: RuntimeEnv): void {
@@ -140,9 +201,10 @@ export async function sendMediaMeet(
140
201
 
141
202
  const sessionInfo = parseTargetToSessionInfo(to, Number(botUserId));
142
203
  const fileName = media.fileName || "file";
204
+ const contentType = resolveContentType(fileName, media.contentType);
143
205
 
144
206
  log(
145
- `sending media to=${to} fileName=${fileName} size=${media.buffer.length}`,
207
+ `sending media to=${to} fileName=${fileName} size=${media.buffer.length} contentType=${contentType}`,
146
208
  );
147
209
 
148
210
  // 包装进度回调
@@ -161,7 +223,7 @@ export async function sendMediaMeet(
161
223
  const result = await bot.sendMedia(sessionInfo, {
162
224
  buffer: media.buffer,
163
225
  fileName,
164
- contentType: media.contentType || "application/octet-stream",
226
+ contentType,
165
227
  content: text || "",
166
228
  onProgress: progressCallback,
167
229
  });