diff --git a/backend/utils/hash.py b/backend/utils/hash.py index 03ae563..2cfd211 100644 --- a/backend/utils/hash.py +++ b/backend/utils/hash.py @@ -1,3 +1,4 @@ +import hashlib from blake3 import blake3 from blurhash import encode @@ -51,6 +52,27 @@ def compute_string_hash_blake3(string, logger=None): return compute_blake3_hash(string, is_file=False, logger=logger) +def compute_md5_hash(file_path): + """ + Compute the MD5 hash of a file. + + Args: + file_path (str): Path to the file. + + Returns: + str: MD5 hash of the file. + """ + try: + hash_md5 = hashlib.md5() + with open(file_path, "rb") as f: + for chunk in iter(lambda: f.read(4096), b""): + hash_md5.update(chunk) + return hash_md5.hexdigest() + except Exception as e: + tqdm.write(f"Error computing MD5 hash: {e}") + return None + + def compute_blur_hash(image_path, components_x=4, components_y=4, logger=None): """ Compute the BlurHash of an image.