From 7d0d53bead229fdbfe1ee8df34f466dd287aa818 Mon Sep 17 00:00:00 2001 From: passthem Date: Tue, 28 Apr 2026 00:35:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B9=B6=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E4=BA=A7=E7=89=A9=E7=9A=84=E7=94=9F=E5=91=BD?= =?UTF-8?q?=E5=91=A8=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/common/artifact.py | 24 +++++++++++++++++------- konabot/plugins/typst/__init__.py | 3 +++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/konabot/common/artifact.py b/konabot/common/artifact.py index 3f70f61..7ffa8ae 100644 --- a/konabot/common/artifact.py +++ b/konabot/common/artifact.py @@ -50,7 +50,14 @@ class ArtifactDepends: tasks = set() for f in self.callbacks: tasks.add(f(downloaded)) - return await asyncio.gather(*tasks, return_exceptions=True) + result = await asyncio.gather(*tasks, return_exceptions=True) + + for r in result: + if isinstance(r, BaseException): + logger.warning("完成了二进制文件的下载,但是有未捕捉的错误") + logger.exception(r) + + return result class Config(BaseModel): @@ -73,12 +80,7 @@ async def _(): async def _task(artifact: ArtifactDepends): async with semaphore: - downloaded = await ensure_artifact(artifact) - result = await artifact._finished(downloaded) - for r in result: - if isinstance(r, BaseException): - logger.warning("完成了二进制文件的下载,但是有未捕捉的错误") - logger.exception(r) + await ensure_artifact(artifact) tasks: set[asyncio.Task] = set() for a in artifact_list: @@ -116,9 +118,16 @@ async def download_artifact(artifact: ArtifactDepends): f"下载到的二进制的 sha256 与需求不同 TARGET={artifact.target} REQUESTED={artifact.sha256} ACTUAL={m.hexdigest()}" ) + await artifact._finished(True) + async def ensure_artifact(artifact: ArtifactDepends) -> bool: + """ + 确保所需的二进制存在。返回是否下载了这个二进制文件。 + """ + if not artifact.is_corresponding_platform(): + logger.debug(f"所需求的平台不是当前平台,跳过二进制下载 artifact={artifact}") return False if not artifact.target.exists(): @@ -136,6 +145,7 @@ async def ensure_artifact(artifact: ArtifactDepends) -> bool: artifact.target.unlink() await download_artifact(artifact) return True + await artifact._finished(False) return False diff --git a/konabot/plugins/typst/__init__.py b/konabot/plugins/typst/__init__.py index 4de27e7..85dd956 100644 --- a/konabot/plugins/typst/__init__.py +++ b/konabot/plugins/typst/__init__.py @@ -41,6 +41,7 @@ bin_path: Path | None = None @arti_typst_linux.on_finished async def _(downloaded: bool): + logger.debug("安装好了 Linux 版本的 Typst") global bin_path tar_path = arti_typst_linux.target @@ -71,6 +72,7 @@ async def _(downloaded: bool): @arti_typst_windows.on_finished async def _(downloaded: bool): + logger.debug("安装好了 Windows 版本的 Typst") global bin_path zip_path = arti_typst_windows.target bin_path = BINARY_PATH / "typst.exe" @@ -160,6 +162,7 @@ async def _( # 对于本地机器,一般不会在应用启动时自动下载,这里再保证存在 await ensure_artifact(arti_typst_linux) await ensure_artifact(arti_typst_windows) + if bin_path is None or not bin_path.exists(): logger.warning("当前环境不存在 Typst,但仍然调用了") return