diff --git a/src/infrastructure/reporting/generators.py b/src/infrastructure/reporting/generators.py index 4eee172..0c5530e 100644 --- a/src/infrastructure/reporting/generators.py +++ b/src/infrastructure/reporting/generators.py @@ -127,55 +127,6 @@ class ReportGenerator(IReportGenerator): # Fallback: 如果返回的是字符串(可能是URL或路径) logger.info(f"图片生成成功 (String): {image_data}") - # 尝试读取文件转 Base64 (解决 Docker 路径不可达问题) - if not image_data.startswith(("http://", "https://")): - try: - import os - - if os.path.exists(image_data): - with open(image_data, "rb") as f: - file_bytes = f.read() - - # 校验是否为有效图片 (防止发送 "Internal Server Error" 文本) - is_valid_image = False - if file_bytes.startswith(b"\xff\xd8"): # JPEG - is_valid_image = True - elif file_bytes.startswith( - b"\x89PNG\r\n\x1a\n" - ): # PNG - is_valid_image = True - - if not is_valid_image: - try: - text_content = file_bytes.decode( - "utf-8" - ) - if ( - "Error" in text_content - or "Exception" in text_content - ): - logger.error( - f"渲染器生成了错误文件而非图片: {text_content[:200]}" - ) - return None, html_content - except Exception: - pass - logger.warning( - f"生成的图片文件头异常 (非JPEG/PNG): {file_bytes[:10].hex()}" - ) - return None, html_content - - b64 = base64.b64encode(file_bytes).decode( - "utf-8" - ) - image_url = f"base64://{b64}" - logger.info( - f"本地图片转 Base64 成功: {len(file_bytes)} bytes" - ) - return image_url, html_content - except Exception as e: - logger.warning(f"尝试读取本地图片失败: {e}") - return image_data, html_content logger.warning(f"渲染策略 {image_options} 返回空数据")