vanshi-sdk 1.0.6 → 1.0.7

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/README.md CHANGED
@@ -166,7 +166,7 @@ if (file) {
166
166
  | `type` | `string` | 消息类型 |
167
167
  | `message` | `string` | 消息内容 |
168
168
  | `sentStatus` | `number` | 本地发送状态,`0` 表示发送中 |
169
- | `fileName` | `string` | 文件名,最长 20 个字符;上传接口也使用截取后的文件名 |
169
+ | `fileName` | `string` | 文件名主名称最长 20 个字符,文件后缀完整保留;上传接口也使用截取后的文件名 |
170
170
  | `fileSize` | `string` | 文件大小 |
171
171
  | `localPreviewUrl` | `string` | 浏览器本地预览地址 |
172
172
 
package/dist/index.cjs CHANGED
@@ -789,8 +789,21 @@ function withClientBizId(message) {
789
789
  clientBizId: message.clientBizId || generateClientBizId()
790
790
  };
791
791
  }
792
+ function sliceChars(value, length) {
793
+ return Array.from(value).slice(0, length).join("");
794
+ }
795
+ function getCharLength(value) {
796
+ return Array.from(value).length;
797
+ }
792
798
  function truncateFileName(fileName) {
793
- return fileName.length > MAX_FILE_NAME_LENGTH ? fileName.slice(0, MAX_FILE_NAME_LENGTH) : fileName;
799
+ const lastDotIndex = fileName.lastIndexOf(".");
800
+ const hasExtension = lastDotIndex > 0 && lastDotIndex < fileName.length - 1;
801
+ if (!hasExtension) {
802
+ return getCharLength(fileName) > MAX_FILE_NAME_LENGTH ? sliceChars(fileName, MAX_FILE_NAME_LENGTH) : fileName;
803
+ }
804
+ const baseName = fileName.slice(0, lastDotIndex);
805
+ const extension = fileName.slice(lastDotIndex);
806
+ return `${sliceChars(baseName, MAX_FILE_NAME_LENGTH)}${extension}`;
794
807
  }
795
808
  function getDisplayFileName(file, fallback = "") {
796
809
  return truncateFileName(file?.name || fallback || "");
package/dist/index.js CHANGED
@@ -4157,8 +4157,21 @@ var VanshiSdk = (() => {
4157
4157
  clientBizId: message.clientBizId || generateClientBizId()
4158
4158
  };
4159
4159
  }
4160
+ function sliceChars(value2, length) {
4161
+ return Array.from(value2).slice(0, length).join("");
4162
+ }
4163
+ function getCharLength(value2) {
4164
+ return Array.from(value2).length;
4165
+ }
4160
4166
  function truncateFileName(fileName) {
4161
- return fileName.length > MAX_FILE_NAME_LENGTH ? fileName.slice(0, MAX_FILE_NAME_LENGTH) : fileName;
4167
+ const lastDotIndex = fileName.lastIndexOf(".");
4168
+ const hasExtension = lastDotIndex > 0 && lastDotIndex < fileName.length - 1;
4169
+ if (!hasExtension) {
4170
+ return getCharLength(fileName) > MAX_FILE_NAME_LENGTH ? sliceChars(fileName, MAX_FILE_NAME_LENGTH) : fileName;
4171
+ }
4172
+ const baseName = fileName.slice(0, lastDotIndex);
4173
+ const extension = fileName.slice(lastDotIndex);
4174
+ return `${sliceChars(baseName, MAX_FILE_NAME_LENGTH)}${extension}`;
4162
4175
  }
4163
4176
  function getDisplayFileName(file, fallback = "") {
4164
4177
  return truncateFileName(file?.name || fallback || "");
package/dist/index.mjs CHANGED
@@ -732,8 +732,21 @@ function withClientBizId(message) {
732
732
  clientBizId: message.clientBizId || generateClientBizId()
733
733
  };
734
734
  }
735
+ function sliceChars(value, length) {
736
+ return Array.from(value).slice(0, length).join("");
737
+ }
738
+ function getCharLength(value) {
739
+ return Array.from(value).length;
740
+ }
735
741
  function truncateFileName(fileName) {
736
- return fileName.length > MAX_FILE_NAME_LENGTH ? fileName.slice(0, MAX_FILE_NAME_LENGTH) : fileName;
742
+ const lastDotIndex = fileName.lastIndexOf(".");
743
+ const hasExtension = lastDotIndex > 0 && lastDotIndex < fileName.length - 1;
744
+ if (!hasExtension) {
745
+ return getCharLength(fileName) > MAX_FILE_NAME_LENGTH ? sliceChars(fileName, MAX_FILE_NAME_LENGTH) : fileName;
746
+ }
747
+ const baseName = fileName.slice(0, lastDotIndex);
748
+ const extension = fileName.slice(lastDotIndex);
749
+ return `${sliceChars(baseName, MAX_FILE_NAME_LENGTH)}${extension}`;
737
750
  }
738
751
  function getDisplayFileName(file, fallback = "") {
739
752
  return truncateFileName(file?.name || fallback || "");
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "private": false,
3
3
  "type": "module",
4
4
  "name": "vanshi-sdk",
5
- "version": "1.0.6",
5
+ "version": "1.0.7",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
8
8
  "browser": "./dist/index.js",