From 12074def77e177741da81c891bd4671c38a41247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Fri, 27 Mar 2026 22:14:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=AE=A1=E7=AE=97hash=E6=97=B6crypto.subtle?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/web-antd/src/utils/oss-upload.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ecom-dmb-frontend/apps/web-antd/src/utils/oss-upload.ts b/ecom-dmb-frontend/apps/web-antd/src/utils/oss-upload.ts index 2d0af6df..82b84713 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/utils/oss-upload.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/utils/oss-upload.ts @@ -25,7 +25,16 @@ export interface UploadOptions { */ async function calculateFileHash(file: File): Promise { const arrayBuffer = await file.arrayBuffer(); - const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer); + // 兼容不同环境的 crypto.subtle + const cryptoSubtle = typeof crypto !== 'undefined' && crypto.subtle + ? crypto.subtle + : (window as any).crypto?.subtle; + + if (!cryptoSubtle) { + throw new Error('当前环境不支持文件加密计算,请使用现代浏览器'); + } + + const hashBuffer = await cryptoSubtle.digest('SHA-256', arrayBuffer); const hashArray = [...new Uint8Array(hashBuffer)]; const hashHex = hashArray .map((b) => b.toString(16).padStart(2, '0'))