refactor(front): replace MD5 with SHA1 for user avatar generation and update related components to use native hash calculation

This commit is contained in:
keven1024
2026-04-09 00:02:56 +08:00
parent 809e38a9c0
commit c58dfa01c6
3 changed files with 18 additions and 12 deletions

View File

@@ -13,10 +13,7 @@ const calcFileHash = async (props: CalcFileHashProps) => {
if (engine === 'native') {
const buffer = await file.arrayBuffer()
const hashBuffer = await crypto.subtle.digest('SHA-1', buffer)
return Array.from(new Uint8Array(hashBuffer))
.map((b) => b.toString(16).padStart(2, '0'))
.join('')
return calcNativeHash(buffer)
}
const chunkBytes = chunkSize * 1024 * 1024
@@ -31,4 +28,11 @@ const calcFileHash = async (props: CalcFileHashProps) => {
return hasher.digest('hex')
}
export const calcNativeHash = async (buffer: BufferSource) => {
const hashBuffer = await crypto.subtle.digest('SHA-1', buffer)
return Array.from(new Uint8Array(hashBuffer))
.map((b) => b.toString(16).padStart(2, '0'))
.join('')
}
export default calcFileHash