From c3192351da9433bde05814a2d49c8ece9b94e355 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sat, 12 Apr 2025 11:59:40 +0800 Subject: [PATCH] feat: Add support for reading SHA256 from .sha256 file in get_file_info function --- py/utils/file_utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/py/utils/file_utils.py b/py/utils/file_utils.py index 1a9825a2..366d1c56 100644 --- a/py/utils/file_utils.py +++ b/py/utils/file_utils.py @@ -93,6 +93,17 @@ async def get_file_info(file_path: str, model_class: Type[BaseModelMetadata] = L logger.debug(f"Using SHA256 from .json file for {file_path}") except Exception as e: logger.error(f"Error reading .json file for {file_path}: {e}") + + # If SHA256 is still not found, check for a .sha256 file + if sha256 is None: + sha256_file = f"{os.path.splitext(file_path)[0]}.sha256" + if os.path.exists(sha256_file): + try: + with open(sha256_file, 'r', encoding='utf-8') as f: + sha256 = f.read().strip().lower() + logger.debug(f"Using SHA256 from .sha256 file for {file_path}") + except Exception as e: + logger.error(f"Error reading .sha256 file for {file_path}: {e}") try: # If we didn't get SHA256 from the .json file, calculate it