|
8 | 8 | import zipfile
|
9 | 9 | import uuid
|
10 | 10 | import psutil
|
| 11 | +import logging |
11 | 12 |
|
12 | 13 | import certifi
|
13 | 14 |
|
|
16 | 17 | from PIL import Image
|
17 | 18 | from .astrbot_path import get_astrbot_data_path
|
18 | 19 |
|
| 20 | +logger = logging.getLogger("astrbot") |
| 21 | + |
19 | 22 |
|
20 | 23 | def on_error(func, path, exc_info):
|
21 | 24 | """
|
@@ -212,19 +215,50 @@ async def get_dashboard_version():
|
212 | 215 | return None
|
213 | 216 |
|
214 | 217 |
|
215 |
| -async def download_dashboard(path: str = None, extract_path: str = "data"): |
| 218 | +async def download_dashboard( |
| 219 | + path: str | None = None, |
| 220 | + extract_path: str = "data", |
| 221 | + latest: bool = True, |
| 222 | + version: str | None = None, |
| 223 | + proxy: str | None = None, |
| 224 | +): |
216 | 225 | """下载管理面板文件"""
|
217 | 226 | if path is None:
|
218 | 227 | path = os.path.join(get_astrbot_data_path(), "dashboard.zip")
|
219 | 228 |
|
220 |
| - dashboard_release_url = "https://astrbot-registry.soulter.top/download/astrbot-dashboard/latest/dist.zip" |
221 |
| - try: |
222 |
| - await download_file(dashboard_release_url, path, show_progress=True) |
223 |
| - except BaseException as _: |
224 |
| - dashboard_release_url = ( |
225 |
| - "https://github.com/Soulter/AstrBot/releases/latest/download/dist.zip" |
| 229 | + if latest or len(str(version)) != 40: |
| 230 | + logger.info("准备下载最新发行版本的 AstrBot WebUI") |
| 231 | + ver_name = "latest" if latest else version |
| 232 | + dashboard_release_url = f"https://astrbot-registry.soulter.top/download/astrbot-dashboard/{ver_name}/dist.zip" |
| 233 | + try: |
| 234 | + await download_file(dashboard_release_url, path, show_progress=True) |
| 235 | + except BaseException as _: |
| 236 | + if latest: |
| 237 | + dashboard_release_url = "https://github.com/Soulter/AstrBot/releases/latest/download/dist.zip" |
| 238 | + else: |
| 239 | + dashboard_release_url = f"https://github.com/Soulter/AstrBot/releases/download/{version}/dist.zip" |
| 240 | + if proxy: |
| 241 | + dashboard_release_url = f"{proxy}/{dashboard_release_url}" |
| 242 | + await download_file(dashboard_release_url, path, show_progress=True) |
| 243 | + else: |
| 244 | + logger.info(f"准备下载指定版本的 AstrBot WebUI: {version}") |
| 245 | + |
| 246 | + url = ( |
| 247 | + "https://api.github.com/repos/AstrBotDevs/astrbot-release-harbour/releases" |
226 | 248 | )
|
227 |
| - await download_file(dashboard_release_url, path, show_progress=True) |
228 |
| - print("解压管理面板文件中...") |
| 249 | + if proxy: |
| 250 | + url = f"{proxy}/{url}" |
| 251 | + async with aiohttp.ClientSession(trust_env=True) as session: |
| 252 | + async with session.get(url) as resp: |
| 253 | + if resp.status == 200: |
| 254 | + releases = await resp.json() |
| 255 | + for release in releases: |
| 256 | + if version in release["tag_name"]: |
| 257 | + download_url = release["assets"][0]["browser_download_url"] |
| 258 | + await download_file(download_url, path, show_progress=True) |
| 259 | + else: |
| 260 | + logger.warning(f"未找到指定的版本的 Dashboard 构建文件: {version}") |
| 261 | + return |
| 262 | + |
229 | 263 | with zipfile.ZipFile(path, "r") as z:
|
230 | 264 | z.extractall(extract_path)
|
0 commit comments