sa2kit 1.6.98 → 1.6.100

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.js CHANGED
@@ -16026,11 +16026,13 @@ var UniversalExportClient = class {
16026
16026
  * 转换API返回的导出结果
16027
16027
  */
16028
16028
  transformExportResultFromAPI(apiResult) {
16029
+ const fileBlob = this.createFileBlobFromBase64(apiResult.fileData, apiResult.fileName);
16029
16030
  return {
16030
16031
  exportId: apiResult.exportId,
16031
16032
  fileName: apiResult.fileName,
16032
16033
  fileSize: apiResult.fileSize,
16033
16034
  fileUrl: apiResult.fileUrl,
16035
+ fileBlob,
16034
16036
  exportedRows: apiResult.exportedRows,
16035
16037
  startTime: new Date(apiResult.startTime),
16036
16038
  endTime: new Date(apiResult.endTime),
@@ -16038,6 +16040,57 @@ var UniversalExportClient = class {
16038
16040
  statistics: apiResult.statistics
16039
16041
  };
16040
16042
  }
16043
+ /**
16044
+ * 将后端返回的base64文件数据转换为Blob
16045
+ */
16046
+ createFileBlobFromBase64(fileData, fileName) {
16047
+ if (!fileData || typeof fileData !== "string") {
16048
+ return void 0;
16049
+ }
16050
+ try {
16051
+ if (typeof atob === "function") {
16052
+ const binaryString = atob(fileData);
16053
+ const bytes = new Uint8Array(binaryString.length);
16054
+ for (let i = 0; i < binaryString.length; i++) {
16055
+ bytes[i] = binaryString.charCodeAt(i);
16056
+ }
16057
+ const arrayBuffer = bytes.buffer.slice(
16058
+ bytes.byteOffset,
16059
+ bytes.byteOffset + bytes.byteLength
16060
+ );
16061
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
16062
+ } else if (typeof Buffer !== "undefined") {
16063
+ const bufferBytes = Buffer.from(fileData, "base64");
16064
+ const bytes = Uint8Array.from(bufferBytes);
16065
+ const arrayBuffer = bytes.buffer.slice(
16066
+ bytes.byteOffset,
16067
+ bytes.byteOffset + bytes.byteLength
16068
+ );
16069
+ return new Blob([arrayBuffer], { type: this.getMimeTypeByFileName(fileName) });
16070
+ } else {
16071
+ return void 0;
16072
+ }
16073
+ } catch {
16074
+ return void 0;
16075
+ }
16076
+ }
16077
+ /**
16078
+ * 根据文件名推断MIME类型
16079
+ */
16080
+ getMimeTypeByFileName(fileName) {
16081
+ const extension = fileName?.split(".").pop()?.toLowerCase();
16082
+ switch (extension) {
16083
+ case "csv":
16084
+ return "text/csv; charset=utf-8";
16085
+ case "xlsx":
16086
+ case "xls":
16087
+ return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
16088
+ case "json":
16089
+ return "application/json; charset=utf-8";
16090
+ default:
16091
+ return "application/octet-stream";
16092
+ }
16093
+ }
16041
16094
  /**
16042
16095
  * 转换API返回的进度数据
16043
16096
  */