perf: 使用 astrbot-registry 下载面板静态资源

This commit is contained in:
Soulter
2024-12-18 21:24:39 +08:00
parent ec61aa1b6f
commit 73494e0d7d
+8 -26
View File
@@ -40,37 +40,19 @@ async def check_dashboard_files():
'''下载管理面板文件'''
if os.path.exists("data/dist"):
return
dashboard_release_url = "https://api.github.com/repos/Soulter/AstrBot-Dashboard/releases/latest"
logger.info("正在获取管理面板最新版本信息,请稍等片刻...")
dashboard_release_url = "https://astrbot-registry.soulter.top/download/astrbot-dashboard/latest/dist.zip"
logger.info("开始下载管理面板文件...")
async with aiohttp.ClientSession() as session:
async with session.get(dashboard_release_url) as resp:
if resp.status != 200:
logger.error(f"获取管理面板最新版本信息失败: {resp.status}")
return
release_info = await resp.json()
download_url = release_info["assets"][0]["browser_download_url"]
mirrors = ["https://ghp.ci/"]
for i in range(len(mirrors)):
mirrors[i] += download_url
mirrors.append(download_url)
ok = False
for mirror in mirrors:
logger.info(f"正在从 GitHub 下载管理面板文件: {mirror}")
async with aiohttp.ClientSession() as session:
async with session.get(mirror) as resp:
if resp.status != 200:
logger.error(f"下载管理面板文件失败: {resp.status}")
continue
with open("data/dashboard.zip", "wb") as f:
f.write(await resp.read())
logger.info("管理面板文件下载完成。")
ok = True
break
logger.error(f"下载管理面板文件失败: {resp.status}")
with open("data/dashboard.zip", "wb") as f:
f.write(await resp.read())
logger.info("管理面板文件下载完成。")
ok = True
if not ok:
logger.fatal(f"下载管理面板文件失败,请手动前往 {download_url} 下载,并将其中的 dist 文件夹解压到 data 目录下。")
logger.critical("下载管理面板文件失败")
return
# unzip