|
@@ -418,11 +418,25 @@ const handleRemove = (file: any, fileList: any) => {
|
|
|
}
|
|
|
|
|
|
async function calculateFileHash(file: File) {
|
|
|
- const arrayBuffer = await file.arrayBuffer();
|
|
|
- const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
|
|
|
- const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
|
- const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
|
- return hashHex;
|
|
|
+ // const arrayBuffer = await file.arrayBuffer();
|
|
|
+ // const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
|
|
|
+ // const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
|
+ // const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
|
+ // return hashHex;
|
|
|
+ // 使用 crypto-js 计算哈希值
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.readAsArrayBuffer(file);
|
|
|
+ reader.onload = function (e) {
|
|
|
+ const arrayBuffer = e.target?.result;
|
|
|
+ const wordArray = CryptoJS.lib.WordArray.create(arrayBuffer);
|
|
|
+ const hashHex = CryptoJS.SHA256(wordArray).toString(CryptoJS.enc.hex);
|
|
|
+ resolve(hashHex);
|
|
|
+ };
|
|
|
+ reader.onerror = () => {
|
|
|
+ reject('');
|
|
|
+ };
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function handleImportFiles(filesList: any[]) {
|