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.
@@ -4097,6 +4097,45 @@ var normalizePreviewBlobResponse = (response) => {
4097
4097
  if (blob) return blob;
4098
4098
  throw new Error(getBinaryResponseMessage(payload) || "\u6587\u4EF6\u5185\u5BB9\u54CD\u5E94\u4E0D\u662F\u4E8C\u8FDB\u5236\u6570\u636E");
4099
4099
  };
4100
+ 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);
4101
+ var decodeBase64ZipBlob = async (blob) => {
4102
+ const prefix = (await blob.slice(0, 96).text()).replace(/^\uFEFF/, "").replace(/\s+/g, "");
4103
+ if (!prefix.startsWith("UEsDB")) return blob;
4104
+ if (blob.size > 32 * 1024 * 1024) {
4105
+ throw new Error("Base64 \u6587\u4EF6\u8D85\u8FC7\u6D4F\u89C8\u5668\u517C\u5BB9\u89E3\u7801\u4E0A\u9650");
4106
+ }
4107
+ const base64 = (await blob.text()).replace(/^\uFEFF/, "").replace(/\s+/g, "");
4108
+ if (!/^[A-Za-z0-9+/]+={0,2}$/.test(base64)) {
4109
+ throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
4110
+ }
4111
+ let binary = "";
4112
+ try {
4113
+ binary = globalThis.atob(base64);
4114
+ } catch {
4115
+ throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
4116
+ }
4117
+ const bytes = new Uint8Array(binary.length);
4118
+ for (let index = 0; index < binary.length; index += 1) {
4119
+ bytes[index] = binary.charCodeAt(index);
4120
+ }
4121
+ if (!isZipBytes(bytes)) {
4122
+ throw new Error("Base64 \u6587\u4EF6\u89E3\u7801\u540E\u4E0D\u662F\u6709\u6548\u7684 Office \u6587\u6863");
4123
+ }
4124
+ if (globalThis.btoa(binary).replace(/=+$/, "") !== base64.replace(/=+$/, "")) {
4125
+ throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
4126
+ }
4127
+ return new Blob([bytes], { type: blob.type || "application/zip" });
4128
+ };
4129
+ var normalizePreviewBlobContent = async (response) => {
4130
+ const blob = normalizePreviewBlobResponse(response);
4131
+ if (String(blob.type || "").toLowerCase().includes("application/json")) {
4132
+ const payload = await blob.text().then((value) => JSON.parse(value)).catch(() => null);
4133
+ if (payload) {
4134
+ throw new Error(getBinaryResponseMessage(payload) || "\u6587\u4EF6\u5185\u5BB9\u8BF7\u6C42\u5931\u8D25");
4135
+ }
4136
+ }
4137
+ return decodeBase64ZipBlob(blob);
4138
+ };
4100
4139
  var isDirectStorageItem = (item) => item.provider === "oss" || item.uploadProvider === "oss" || item.uploadProvider === "builtin-oss" || Boolean(item.storageCode);
4101
4140
  var getPreviewItemKey = (item, index = 0) => getAttachmentItemIdentity(item) || item.id || item.uid || `${item.name || "file"}-${index}`;
4102
4141
  var getPreviewSourceUrl = (item) => item.previewUrl || item.publicUrl || item.url || "";
@@ -4270,7 +4309,7 @@ var prepareFilePreview = async (options) => {
4270
4309
  };
4271
4310
  var loadPreviewBlob = async (request, url) => {
4272
4311
  const response = await request({ url, method: "get", responseType: "blob" });
4273
- return normalizePreviewBlobResponse(response);
4312
+ return normalizePreviewBlobContent(response);
4274
4313
  };
4275
4314
  var convertHeicPreview = async (request, url) => {
4276
4315
  const source = await loadPreviewBlob(request, url);