fix(build): 补齐 hash 工具并新增 AGENTS 规范
This commit is contained in:
21
frontend/src/utils/hash.ts
Normal file
21
frontend/src/utils/hash.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export async function sha256HexOfBlob(blob: Blob): Promise<string | null> {
|
||||
if (!('crypto' in globalThis) || !globalThis.crypto?.subtle) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const buffer = await blob.arrayBuffer();
|
||||
const digest = await globalThis.crypto.subtle.digest('SHA-256', buffer);
|
||||
return bytesToHex(new Uint8Array(digest));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function bytesToHex(bytes: Uint8Array): string {
|
||||
let hex = '';
|
||||
for (const byte of bytes) {
|
||||
hex += byte.toString(16).padStart(2, '0');
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
Reference in New Issue
Block a user