feat(front): implement engine detection for file hash calculation and add error handling for unsupported environments

This commit is contained in:
keven1024
2026-04-11 09:05:30 +08:00
parent 3312b304f9
commit e42fe477d1
9 changed files with 27 additions and 2 deletions

View File

@@ -35,4 +35,15 @@ export const calcNativeHash = async (buffer: BufferSource) => {
.join('')
}
export const detectSupportedEngines = (): ('native' | 'wasm')[] => {
const engines: ('native' | 'wasm')[] = []
if (typeof crypto !== 'undefined' && typeof crypto.subtle !== 'undefined') {
engines.push('native')
}
if (typeof WebAssembly !== 'undefined' && typeof WebAssembly.instantiate === 'function') {
engines.push('wasm')
}
return engines
}
export default calcFileHash