liangzimixin 0.3.36 → 0.3.38

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/dist/index.cjs CHANGED
@@ -17956,6 +17956,56 @@ function detectFileType(fileName) {
17956
17956
  if (VIDEO_EXTS.has(ext)) return "video";
17957
17957
  return "file";
17958
17958
  }
17959
+ var MIME_MAP = {
17960
+ // 图片
17961
+ ".jpg": "image/jpeg",
17962
+ ".jpeg": "image/jpeg",
17963
+ ".png": "image/png",
17964
+ ".gif": "image/gif",
17965
+ ".bmp": "image/bmp",
17966
+ ".webp": "image/webp",
17967
+ ".svg": "image/svg+xml",
17968
+ ".ico": "image/x-icon",
17969
+ ".tiff": "image/tiff",
17970
+ ".tif": "image/tiff",
17971
+ // 音频
17972
+ ".mp3": "audio/mpeg",
17973
+ ".wav": "audio/wav",
17974
+ ".ogg": "audio/ogg",
17975
+ ".opus": "audio/opus",
17976
+ ".flac": "audio/flac",
17977
+ ".aac": "audio/aac",
17978
+ ".m4a": "audio/mp4",
17979
+ ".wma": "audio/x-ms-wma",
17980
+ // 视频
17981
+ ".mp4": "video/mp4",
17982
+ ".mov": "video/quicktime",
17983
+ ".avi": "video/x-msvideo",
17984
+ ".mkv": "video/x-matroska",
17985
+ ".wmv": "video/x-ms-wmv",
17986
+ ".flv": "video/x-flv",
17987
+ ".webm": "video/webm",
17988
+ ".m4v": "video/mp4",
17989
+ // 文档
17990
+ ".pdf": "application/pdf",
17991
+ ".doc": "application/msword",
17992
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
17993
+ ".xls": "application/vnd.ms-excel",
17994
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
17995
+ ".ppt": "application/vnd.ms-powerpoint",
17996
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
17997
+ ".txt": "text/plain",
17998
+ ".csv": "text/csv",
17999
+ ".json": "application/json",
18000
+ ".zip": "application/zip",
18001
+ ".rar": "application/x-rar-compressed",
18002
+ ".7z": "application/x-7z-compressed",
18003
+ ".gz": "application/gzip"
18004
+ };
18005
+ function inferMimeType(fileName) {
18006
+ const ext = path.extname(fileName).toLowerCase();
18007
+ return MIME_MAP[ext] || "application/octet-stream";
18008
+ }
17959
18009
  async function resolveAndUploadMedia(params) {
17960
18010
  const {
17961
18011
  mediaUrl,
@@ -18005,12 +18055,14 @@ async function resolveAndUploadMedia(params) {
18005
18055
  });
18006
18056
  }
18007
18057
  const fileType = detectFileType(fileName);
18008
- log3.info("media:fileType", { fileName, fileType });
18058
+ const mimeType = inferMimeType(fileName);
18059
+ log3.info("media:fileType", { fileName, fileType, mimeType });
18009
18060
  let uploadResult;
18010
18061
  try {
18011
18062
  uploadResult = await uploadMedia({
18012
18063
  file: buffer,
18013
18064
  fileName,
18065
+ mimeType,
18014
18066
  tokenManager,
18015
18067
  serverUrl,
18016
18068
  maxFileSizeMb,
@@ -18027,7 +18079,14 @@ async function resolveAndUploadMedia(params) {
18027
18079
  };
18028
18080
  }
18029
18081
  const msgType = fileType;
18030
- const contentPayload = fileType === "file" ? { fileId: uploadResult.fileKey, fileName, size: uploadResult.fileSize } : { fileId: uploadResult.fileKey };
18082
+ let contentPayload;
18083
+ if (fileType === "file") {
18084
+ contentPayload = { fileId: uploadResult.fileKey, fileName, size: uploadResult.fileSize, mimeType };
18085
+ } else if (fileType === "image") {
18086
+ contentPayload = { fileId: uploadResult.fileKey };
18087
+ } else {
18088
+ contentPayload = { fileId: uploadResult.fileKey, mimeType };
18089
+ }
18031
18090
  await messagePipe.sendMessage({
18032
18091
  chatId,
18033
18092
  senderId: chatId,
@@ -19861,7 +19920,9 @@ var WSClient = class extends import_node_events.EventEmitter {
19861
19920
  log19.info("ws:connecting", { url: url2 });
19862
19921
  return new Promise((resolve3, reject) => {
19863
19922
  const ws = new wrapper_default(url2, protocols, { headers });
19923
+ let connected = false;
19864
19924
  ws.on("open", () => {
19925
+ connected = true;
19865
19926
  log19.info("ws:connected", { url: url2 });
19866
19927
  this.emit("open");
19867
19928
  resolve3();
@@ -19879,7 +19940,7 @@ var WSClient = class extends import_node_events.EventEmitter {
19879
19940
  ws.on("error", (err) => {
19880
19941
  log19.error("ws:error", { error: err.message });
19881
19942
  this.emit("error", err);
19882
- if (this.ws !== ws) {
19943
+ if (!connected) {
19883
19944
  reject(err);
19884
19945
  }
19885
19946
  });
@@ -20311,6 +20372,7 @@ var ConnectionManager = class {
20311
20372
  });
20312
20373
  this.client.on("pong", () => {
20313
20374
  this.pongReceived = true;
20375
+ log22.info("heartbeat: pong received");
20314
20376
  });
20315
20377
  }
20316
20378
  /** 启动心跳保活 — 定时发送 WebSocket Ping 帧 */
@@ -20331,7 +20393,7 @@ var ConnectionManager = class {
20331
20393
  }
20332
20394
  this.pongReceived = false;
20333
20395
  this.client.ping();
20334
- log22.debug?.("heartbeat: ping sent");
20396
+ log22.info("heartbeat: ping sent");
20335
20397
  }, this.options.heartbeatIntervalMs);
20336
20398
  }
20337
20399
  /** 停止心跳定时器 */
@@ -4051,6 +4051,56 @@ function detectFileType(fileName) {
4051
4051
  if (VIDEO_EXTS.has(ext)) return "video";
4052
4052
  return "file";
4053
4053
  }
4054
+ var MIME_MAP = {
4055
+ // 图片
4056
+ ".jpg": "image/jpeg",
4057
+ ".jpeg": "image/jpeg",
4058
+ ".png": "image/png",
4059
+ ".gif": "image/gif",
4060
+ ".bmp": "image/bmp",
4061
+ ".webp": "image/webp",
4062
+ ".svg": "image/svg+xml",
4063
+ ".ico": "image/x-icon",
4064
+ ".tiff": "image/tiff",
4065
+ ".tif": "image/tiff",
4066
+ // 音频
4067
+ ".mp3": "audio/mpeg",
4068
+ ".wav": "audio/wav",
4069
+ ".ogg": "audio/ogg",
4070
+ ".opus": "audio/opus",
4071
+ ".flac": "audio/flac",
4072
+ ".aac": "audio/aac",
4073
+ ".m4a": "audio/mp4",
4074
+ ".wma": "audio/x-ms-wma",
4075
+ // 视频
4076
+ ".mp4": "video/mp4",
4077
+ ".mov": "video/quicktime",
4078
+ ".avi": "video/x-msvideo",
4079
+ ".mkv": "video/x-matroska",
4080
+ ".wmv": "video/x-ms-wmv",
4081
+ ".flv": "video/x-flv",
4082
+ ".webm": "video/webm",
4083
+ ".m4v": "video/mp4",
4084
+ // 文档
4085
+ ".pdf": "application/pdf",
4086
+ ".doc": "application/msword",
4087
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
4088
+ ".xls": "application/vnd.ms-excel",
4089
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
4090
+ ".ppt": "application/vnd.ms-powerpoint",
4091
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
4092
+ ".txt": "text/plain",
4093
+ ".csv": "text/csv",
4094
+ ".json": "application/json",
4095
+ ".zip": "application/zip",
4096
+ ".rar": "application/x-rar-compressed",
4097
+ ".7z": "application/x-7z-compressed",
4098
+ ".gz": "application/gzip"
4099
+ };
4100
+ function inferMimeType(fileName) {
4101
+ const ext = path.extname(fileName).toLowerCase();
4102
+ return MIME_MAP[ext] || "application/octet-stream";
4103
+ }
4054
4104
  async function resolveAndUploadMedia(params) {
4055
4105
  const {
4056
4106
  mediaUrl,
@@ -4100,12 +4150,14 @@ async function resolveAndUploadMedia(params) {
4100
4150
  });
4101
4151
  }
4102
4152
  const fileType = detectFileType(fileName);
4103
- log3.info("media:fileType", { fileName, fileType });
4153
+ const mimeType = inferMimeType(fileName);
4154
+ log3.info("media:fileType", { fileName, fileType, mimeType });
4104
4155
  let uploadResult;
4105
4156
  try {
4106
4157
  uploadResult = await uploadMedia({
4107
4158
  file: buffer,
4108
4159
  fileName,
4160
+ mimeType,
4109
4161
  tokenManager,
4110
4162
  serverUrl,
4111
4163
  maxFileSizeMb,
@@ -4122,7 +4174,14 @@ async function resolveAndUploadMedia(params) {
4122
4174
  };
4123
4175
  }
4124
4176
  const msgType = fileType;
4125
- const contentPayload = fileType === "file" ? { fileId: uploadResult.fileKey, fileName, size: uploadResult.fileSize } : { fileId: uploadResult.fileKey };
4177
+ let contentPayload;
4178
+ if (fileType === "file") {
4179
+ contentPayload = { fileId: uploadResult.fileKey, fileName, size: uploadResult.fileSize, mimeType };
4180
+ } else if (fileType === "image") {
4181
+ contentPayload = { fileId: uploadResult.fileKey };
4182
+ } else {
4183
+ contentPayload = { fileId: uploadResult.fileKey, mimeType };
4184
+ }
4126
4185
  await messagePipe.sendMessage({
4127
4186
  chatId,
4128
4187
  senderId: chatId,
@@ -18920,7 +18979,9 @@ var WSClient = class extends import_node_events.EventEmitter {
18920
18979
  log10.info("ws:connecting", { url: url2 });
18921
18980
  return new Promise((resolve3, reject) => {
18922
18981
  const ws = new wrapper_default(url2, protocols, { headers });
18982
+ let connected = false;
18923
18983
  ws.on("open", () => {
18984
+ connected = true;
18924
18985
  log10.info("ws:connected", { url: url2 });
18925
18986
  this.emit("open");
18926
18987
  resolve3();
@@ -18938,7 +18999,7 @@ var WSClient = class extends import_node_events.EventEmitter {
18938
18999
  ws.on("error", (err) => {
18939
19000
  log10.error("ws:error", { error: err.message });
18940
19001
  this.emit("error", err);
18941
- if (this.ws !== ws) {
19002
+ if (!connected) {
18942
19003
  reject(err);
18943
19004
  }
18944
19005
  });
@@ -19370,6 +19431,7 @@ var ConnectionManager = class {
19370
19431
  });
19371
19432
  this.client.on("pong", () => {
19372
19433
  this.pongReceived = true;
19434
+ log13.info("heartbeat: pong received");
19373
19435
  });
19374
19436
  }
19375
19437
  /** 启动心跳保活 — 定时发送 WebSocket Ping 帧 */
@@ -19390,7 +19452,7 @@ var ConnectionManager = class {
19390
19452
  }
19391
19453
  this.pongReceived = false;
19392
19454
  this.client.ping();
19393
- log13.debug?.("heartbeat: ping sent");
19455
+ log13.info("heartbeat: ping sent");
19394
19456
  }, this.options.heartbeatIntervalMs);
19395
19457
  }
19396
19458
  /** 停止心跳定时器 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liangzimixin",
3
- "version": "0.3.36",
3
+ "version": "0.3.38",
4
4
  "description": "Quantum-encrypted IM channel plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",