mirror of
https://github.com/keven1024/015.git
synced 2026-06-06 20:39:35 +00:00
refactor(front): replace MD5 with SHA1 for user avatar generation and update related components to use native hash calculation
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user