优化超时时间
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user