fix(io.py): download_dashboard如果发现没有dist/assets/version文件,下载完毕自动写入(以防万一)

This commit is contained in:
LIghtJUNction
2025-10-26 15:35:25 +08:00
parent 6c7d7c9015
commit 4f4a9b9e55
3 changed files with 25 additions and 8 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ async def check_dashboard(astrbot_root: Path) -> None:
):
click.echo("正在安装管理面板...")
await download_dashboard(
path="data/dashboard.zip",
path="data",
extract_path=str(astrbot_root),
version=f"v{VERSION}",
latest=False,
+23 -7
View File
@@ -1,4 +1,5 @@
import os
from pathlib import Path
import ssl
import shutil
import socket
@@ -150,7 +151,7 @@ async def download_file(url: str, path: str, show_progress: bool = False):
f.write(chunk)
downloaded_size += len(chunk)
if show_progress:
elapsed_time = time.time() - start_time
elapsed_time = time.time() - start_time if time.time() - start_time > 0 else 1
speed = downloaded_size / 1024 / elapsed_time # KB/s
print(
f"\r下载进度: {downloaded_size / total_size:.2%} 速度: {speed:.2f} KB/s",
@@ -221,10 +222,16 @@ async def download_dashboard(
latest: bool = True,
version: str | None = None,
proxy: str | None = None,
):
) -> None:
"""下载管理面板文件"""
if path is None:
path = os.path.join(get_astrbot_data_path(), "dashboard.zip")
_path = Path(get_astrbot_data_path()).absolute()
else:
_path = Path(path).absolute()
zip_path = _path / "dashboard.zip"
version_file = _path / "dist" / "assets" / "version"
if latest or len(str(version)) != 40:
ver_name = "latest" if latest else version
@@ -233,7 +240,7 @@ async def download_dashboard(
f"准备下载指定发行版本的 AstrBot WebUI 文件: {dashboard_release_url}"
)
try:
await download_file(dashboard_release_url, path, show_progress=True)
await download_file(dashboard_release_url, str(zip_path), show_progress=True)
except BaseException as _:
if latest:
dashboard_release_url = "https://github.com/Soulter/AstrBot/releases/latest/download/dist.zip"
@@ -241,12 +248,21 @@ async def download_dashboard(
dashboard_release_url = f"https://github.com/Soulter/AstrBot/releases/download/{version}/dist.zip"
if proxy:
dashboard_release_url = f"{proxy}/{dashboard_release_url}"
await download_file(dashboard_release_url, path, show_progress=True)
await download_file(dashboard_release_url, str(zip_path), show_progress=True)
else:
url = f"https://github.com/AstrBotDevs/astrbot-release-harbour/releases/download/release-{version}/dist.zip"
logger.info(f"准备下载指定版本的 AstrBot WebUI: {url}")
if proxy:
url = f"{proxy}/{url}"
await download_file(url, path, show_progress=True)
with zipfile.ZipFile(path, "r") as z:
await download_file(url, str(zip_path), show_progress=True)
with zipfile.ZipFile(zip_path, "r") as z:
z.extractall(extract_path)
if version_file.exists():
return
# 写入dist/version
# https://github.com/AstrBotDevs/AstrBot/pull/3106
# 实际上压根没有dist/version文件,这里需要写入
with version_file.open("w") as f:
f.write(f"{version}")
+1
View File
@@ -89,6 +89,7 @@ target-version = "py310"
[dependency-groups]
dev = [
"commitizen>=4.9.1",
"pytest>=8.4.1",
"pytest-asyncio>=1.1.0",
"pytest-cov>=6.2.1",