export function calculateFileIdentifier(file: File): Promise<string> {
    return new Promise((resolve, reject) => {
        const reader = new FileReader();

        // 文件读取完成后的处理
        reader.onload = async (e) => {
            try {
                // 获取文件buffer并计算SHA-256哈希
                const buffer = e.target?.result as ArrayBuffer;
                const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);

                // 将哈希buffer转换为16进制字符串
                const hashArray = Array.from(new Uint8Array(hashBuffer));
                const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');

                // 拼接哈希值和文件大小作为标识符
                resolve(`${hashHex}-${file.size}`);
            } catch (error) {
                reject(error);
            }
        };

        // 注册错误处理函数
        reader.onerror = reject;

        // 仅读取文件前2MB用于计算哈希
        reader.readAsArrayBuffer(file.slice(0, 2 * 1024 * 1024));
    });
}