2024-06-29 08:10:02 +02:00
|
|
|
/**
|
|
|
|
|
* @packageDocumentation
|
|
|
|
|
* @module MediaManager/Utils
|
|
|
|
|
*/
|
|
|
|
|
|
2025-03-30 23:06:34 +02:00
|
|
|
import { SHA256 } from "bun";
|
|
|
|
|
|
2024-06-29 08:10:02 +02:00
|
|
|
/**
|
2024-10-03 19:02:13 +02:00
|
|
|
* Generates a SHA-256 hash for a given file.
|
|
|
|
|
* @param file - The file to hash.
|
|
|
|
|
* @returns A promise that resolves to the SHA-256 hash of the file in hex format.
|
2024-06-29 08:10:02 +02:00
|
|
|
*/
|
2024-10-03 19:02:13 +02:00
|
|
|
export const getMediaHash = async (file: File): Promise<string> => {
|
|
|
|
|
const arrayBuffer = await file.arrayBuffer();
|
2025-03-30 23:06:34 +02:00
|
|
|
const hash = new SHA256().update(arrayBuffer).digest("hex");
|
2024-10-03 19:02:13 +02:00
|
|
|
return hash;
|
|
|
|
|
};
|