修复了cdn连接超时问题
This commit is contained in:
@@ -18,6 +18,7 @@ from docutranslate.logger import translater_logger
|
|||||||
from docutranslate.utils.resource_utils import resource_path
|
from docutranslate.utils.resource_utils import resource_path
|
||||||
from docutranslate.global_values import available_packages
|
from docutranslate.global_values import available_packages
|
||||||
|
|
||||||
|
httpx_client = httpx.AsyncClient()
|
||||||
# --- 全局配置 ---
|
# --- 全局配置 ---
|
||||||
log_queue: Optional[asyncio.Queue] = None
|
log_queue: Optional[asyncio.Queue] = None
|
||||||
current_state: Dict[str, Any] = {
|
current_state: Dict[str, Any] = {
|
||||||
@@ -134,10 +135,11 @@ async def _perform_translation(params: Dict[str, Any], file_contents: bytes, ori
|
|||||||
|
|
||||||
md_content = ft.export_to_markdown()
|
md_content = ft.export_to_markdown()
|
||||||
try:
|
try:
|
||||||
httpx.head("https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/contrib/auto-render.min.js", timeout=1)
|
await httpx_client.head("https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/contrib/auto-render.min.js", timeout=3)
|
||||||
html_content = ft.export_to_html(title=current_state["original_filename_stem"], cdn=True)
|
html_content = ft.export_to_html(title=current_state["original_filename_stem"], cdn=True)
|
||||||
except TimeoutError:
|
except (httpx.TimeoutException, httpx.RequestError) as e:
|
||||||
translater_logger.info("无法连接cdn,使用本地js进行pdf渲染")
|
print(f"连接cdn.jsdelivr.net失败,错误信息:{e}")
|
||||||
|
translater_logger.info("无法连接cdn.jsdelivr.net,使用本地js进行pdf渲染")
|
||||||
html_content = ft.export_to_html(title=current_state["original_filename_stem"], cdn=False)
|
html_content = ft.export_to_html(title=current_state["original_filename_stem"], cdn=False)
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
duration = end_time - current_state["task_start_time"]
|
duration = end_time - current_state["task_start_time"]
|
||||||
|
|||||||
Reference in New Issue
Block a user