openxiangda 1.0.153 → 1.0.154

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.
@@ -3667,6 +3667,45 @@ var normalizePreviewBlobResponse = (response) => {
3667
3667
  if (blob) return blob;
3668
3668
  throw new Error(getBinaryResponseMessage(payload) || "\u6587\u4EF6\u5185\u5BB9\u54CD\u5E94\u4E0D\u662F\u4E8C\u8FDB\u5236\u6570\u636E");
3669
3669
  };
3670
+ var isZipBytes = (bytes) => bytes.length >= 4 && bytes[0] === 80 && bytes[1] === 75 && (bytes[2] === 3 && bytes[3] === 4 || bytes[2] === 5 && bytes[3] === 6 || bytes[2] === 7 && bytes[3] === 8);
3671
+ var decodeBase64ZipBlob = async (blob) => {
3672
+ const prefix = (await blob.slice(0, 96).text()).replace(/^\uFEFF/, "").replace(/\s+/g, "");
3673
+ if (!prefix.startsWith("UEsDB")) return blob;
3674
+ if (blob.size > 32 * 1024 * 1024) {
3675
+ throw new Error("Base64 \u6587\u4EF6\u8D85\u8FC7\u6D4F\u89C8\u5668\u517C\u5BB9\u89E3\u7801\u4E0A\u9650");
3676
+ }
3677
+ const base64 = (await blob.text()).replace(/^\uFEFF/, "").replace(/\s+/g, "");
3678
+ if (!/^[A-Za-z0-9+/]+={0,2}$/.test(base64)) {
3679
+ throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
3680
+ }
3681
+ let binary = "";
3682
+ try {
3683
+ binary = globalThis.atob(base64);
3684
+ } catch {
3685
+ throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
3686
+ }
3687
+ const bytes = new Uint8Array(binary.length);
3688
+ for (let index = 0; index < binary.length; index += 1) {
3689
+ bytes[index] = binary.charCodeAt(index);
3690
+ }
3691
+ if (!isZipBytes(bytes)) {
3692
+ throw new Error("Base64 \u6587\u4EF6\u89E3\u7801\u540E\u4E0D\u662F\u6709\u6548\u7684 Office \u6587\u6863");
3693
+ }
3694
+ if (globalThis.btoa(binary).replace(/=+$/, "") !== base64.replace(/=+$/, "")) {
3695
+ throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
3696
+ }
3697
+ return new Blob([bytes], { type: blob.type || "application/zip" });
3698
+ };
3699
+ var normalizePreviewBlobContent = async (response) => {
3700
+ const blob = normalizePreviewBlobResponse(response);
3701
+ if (String(blob.type || "").toLowerCase().includes("application/json")) {
3702
+ const payload = await blob.text().then((value) => JSON.parse(value)).catch(() => null);
3703
+ if (payload) {
3704
+ throw new Error(getBinaryResponseMessage(payload) || "\u6587\u4EF6\u5185\u5BB9\u8BF7\u6C42\u5931\u8D25");
3705
+ }
3706
+ }
3707
+ return decodeBase64ZipBlob(blob);
3708
+ };
3670
3709
  var isDirectStorageItem = (item) => item.provider === "oss" || item.uploadProvider === "oss" || item.uploadProvider === "builtin-oss" || Boolean(item.storageCode);
3671
3710
  var getPreviewItemKey = (item, index = 0) => getAttachmentItemIdentity(item) || item.id || item.uid || `${item.name || "file"}-${index}`;
3672
3711
  var getPreviewSourceUrl = (item) => item.previewUrl || item.publicUrl || item.url || "";
@@ -3840,7 +3879,7 @@ var prepareFilePreview = async (options) => {
3840
3879
  };
3841
3880
  var loadPreviewBlob = async (request, url) => {
3842
3881
  const response = await request({ url, method: "get", responseType: "blob" });
3843
- return normalizePreviewBlobResponse(response);
3882
+ return normalizePreviewBlobContent(response);
3844
3883
  };
3845
3884
  var convertHeicPreview = async (request, url) => {
3846
3885
  const source = await loadPreviewBlob(request, url);