@meet-im/meet 1.1.2 → 1.1.3
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/package.json +1 -1
- package/src/send.ts +55 -2
package/package.json
CHANGED
package/src/send.ts
CHANGED
|
@@ -52,6 +52,57 @@ export function inferContentTypeFromFileName(fileName: string): string | undefin
|
|
|
52
52
|
return mimeMap[ext];
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* 根据 MIME 类型获取文件扩展名
|
|
57
|
+
*/
|
|
58
|
+
function getExtensionFromContentType(contentType: string): string | undefined {
|
|
59
|
+
const mimeToExt: Record<string, string> = {
|
|
60
|
+
"image/jpeg": ".jpg",
|
|
61
|
+
"image/png": ".png",
|
|
62
|
+
"image/gif": ".gif",
|
|
63
|
+
"image/webp": ".webp",
|
|
64
|
+
"image/avif": ".avif",
|
|
65
|
+
"image/heic": ".heic",
|
|
66
|
+
"image/heif": ".heif",
|
|
67
|
+
"image/bmp": ".bmp",
|
|
68
|
+
"image/x-icon": ".ico",
|
|
69
|
+
"image/svg+xml": ".svg",
|
|
70
|
+
"image/tiff": ".tiff",
|
|
71
|
+
"video/mp4": ".mp4",
|
|
72
|
+
"video/webm": ".webm",
|
|
73
|
+
"video/quicktime": ".mov",
|
|
74
|
+
"video/x-msvideo": ".avi",
|
|
75
|
+
"video/x-matroska": ".mkv",
|
|
76
|
+
"audio/mpeg": ".mp3",
|
|
77
|
+
"audio/wav": ".wav",
|
|
78
|
+
"audio/ogg": ".ogg",
|
|
79
|
+
"audio/flac": ".flac",
|
|
80
|
+
"audio/mp4": ".m4a",
|
|
81
|
+
"application/pdf": ".pdf",
|
|
82
|
+
"application/json": ".json",
|
|
83
|
+
"application/xml": ".xml",
|
|
84
|
+
};
|
|
85
|
+
return mimeToExt[contentType];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 确保文件名有正确的扩展名
|
|
90
|
+
* 如果文件名没有扩展名,根据 contentType 添加
|
|
91
|
+
*/
|
|
92
|
+
function ensureFileNameExtension(fileName: string, contentType: string): string {
|
|
93
|
+
// 检查是否已有扩展名
|
|
94
|
+
const hasExtension = /\.[a-zA-Z0-9]+$/.test(fileName);
|
|
95
|
+
if (hasExtension) {
|
|
96
|
+
return fileName;
|
|
97
|
+
}
|
|
98
|
+
// 根据 contentType 添加扩展名
|
|
99
|
+
const ext = getExtensionFromContentType(contentType);
|
|
100
|
+
if (ext) {
|
|
101
|
+
return fileName + ext;
|
|
102
|
+
}
|
|
103
|
+
return fileName;
|
|
104
|
+
}
|
|
105
|
+
|
|
55
106
|
/**
|
|
56
107
|
* 获取最终的 contentType
|
|
57
108
|
* 如果原始 contentType 缺失或为通用二进制流,则根据文件名推断
|
|
@@ -207,8 +258,10 @@ export async function sendMediaMeet(
|
|
|
207
258
|
}
|
|
208
259
|
|
|
209
260
|
const sessionInfo = parseTargetToSessionInfo(to, Number(botUserId));
|
|
210
|
-
const
|
|
211
|
-
const contentType = resolveContentType(
|
|
261
|
+
const rawFileName = media.fileName || "file";
|
|
262
|
+
const contentType = resolveContentType(rawFileName, media.contentType);
|
|
263
|
+
// 确保文件名有正确的扩展名
|
|
264
|
+
const fileName = ensureFileNameExtension(rawFileName, contentType);
|
|
212
265
|
|
|
213
266
|
log(
|
|
214
267
|
`sending media to=${to} fileName=${fileName} size=${media.buffer.length} contentType=${contentType}`,
|