From b685ed3b098a8b391ea2e7ce4330a92e53298a46 Mon Sep 17 00:00:00 2001 From: liuwei Date: Fri, 11 Jul 2025 16:10:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/markdown_to_image.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/markdown_to_image.py b/utils/markdown_to_image.py index 76fe59e..a6f2ce6 100644 --- a/utils/markdown_to_image.py +++ b/utils/markdown_to_image.py @@ -243,7 +243,8 @@ async def html_to_image(html_file, output_image): # 业务逻辑不变 try: page = await browser.new_page() - await page.goto(f'file://{os.path.abspath(html_file)}') + # 增加超时时间到60秒或更长 + await page.goto(f'file://{os.path.abspath(html_file)}', timeout=60000) await page.set_viewport_size({"width": 750, "height": 800}) await page.wait_for_timeout(500) await page.screenshot(path=output_image, full_page=True) @@ -305,6 +306,14 @@ async def convert_md_str_to_image(md_content: str, output_image: str) -> str: # 将 Markdown 转换为 HTML await md_str_to_html(md_content, str(temp_html_path)) + # 添加更长的等待时间确保文件系统同步 + await asyncio.sleep(1.0) + + # 检查文件是否存在和可读 + if not os.path.exists(str(temp_html_path)): + logger.error(f"HTML文件不存在: {temp_html_path}") + raise FileNotFoundError(f"HTML文件不存在: {temp_html_path}") + # 将 HTML 转换为图片 await html_to_image(str(temp_html_path), str(output_image_path))