Skip to content

Commit b1e4bff

Browse files
committed
feat: 支持升级的同时更新到指定版本的 WebUI
1 parent c1202cd commit b1e4bff

File tree

8 files changed

+65
-32
lines changed

8 files changed

+65
-32
lines changed

.github/workflows/dashboard_ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jobs:
2525
echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
2626
mkdir -p dashboard/dist/assets
2727
echo $COMMIT_SHA > dashboard/dist/assets/version
28-
zip -r dashboard/dist.zip dashboard/dist
28+
cd dashboard
29+
zip -r dist.zip dist
2930
3031
- name: Archive production artifacts
3132
uses: actions/upload-artifact@v4

astrbot/core/updator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ async def update(self, reboot=False, latest=True, version=None, proxy=""):
8989
file_url = update_data[0]["zipball_url"]
9090
elif str(version).startswith("v"):
9191
# 更新到指定版本
92-
logger.info(f"正在更新到指定版本: {version}")
9392
for data in update_data:
9493
if data["tag_name"] == version:
9594
file_url = data["zipball_url"]
@@ -98,15 +97,16 @@ async def update(self, reboot=False, latest=True, version=None, proxy=""):
9897
else:
9998
if len(str(version)) != 40:
10099
raise Exception("commit hash 长度不正确,应为 40")
101-
logger.info(f"正在尝试更新到指定 commit: {version}")
102-
file_url = "https://github.com/Soulter/AstrBot/archive/" + version + ".zip"
100+
file_url = f"https://github.com/Soulter/AstrBot/archive/{version}.zip"
101+
logger.info(f"准备更新至指定版本的 AstrBot Core: {version}")
103102

104103
if proxy:
105104
proxy = proxy.removesuffix("/")
106105
file_url = f"{proxy}/{file_url}"
107106

108107
try:
109108
await download_file(file_url, "temp.zip")
109+
logger.info("下载 AstrBot Core 更新文件完成,正在执行解压...")
110110
self.unzip_file("temp.zip", self.MAIN_PATH)
111111
except BaseException as e:
112112
raise e

astrbot/core/utils/io.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import zipfile
99
import uuid
1010
import psutil
11+
import logging
1112

1213
import certifi
1314

@@ -16,6 +17,8 @@
1617
from PIL import Image
1718
from .astrbot_path import get_astrbot_data_path
1819

20+
logger = logging.getLogger("astrbot")
21+
1922

2023
def on_error(func, path, exc_info):
2124
"""
@@ -212,19 +215,50 @@ async def get_dashboard_version():
212215
return None
213216

214217

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+
):
216225
"""下载管理面板文件"""
217226
if path is None:
218227
path = os.path.join(get_astrbot_data_path(), "dashboard.zip")
219228

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"
226248
)
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+
229263
with zipfile.ZipFile(path, "r") as z:
230264
z.extractall(extract_path)

astrbot/core/zip_updator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,13 @@ def unzip_file(self, zip_path: str, target_dir: str):
181181
"""
182182
os.makedirs(target_dir, exist_ok=True)
183183
update_dir = ""
184-
logger.info(f"解压文件: {zip_path}")
185184
with zipfile.ZipFile(zip_path, "r") as z:
186185
update_dir = z.namelist()[0]
187186
z.extractall(target_dir)
187+
logger.debug(f"解压文件完成: {zip_path}")
188188

189189
files = os.listdir(os.path.join(target_dir, update_dir))
190190
for f in files:
191-
logger.info(f"移动更新文件/目录: {f}")
192191
if os.path.isdir(os.path.join(target_dir, update_dir, f)):
193192
if os.path.exists(os.path.join(target_dir, f)):
194193
shutil.rmtree(os.path.join(target_dir, f), onerror=on_error)
@@ -198,13 +197,13 @@ def unzip_file(self, zip_path: str, target_dir: str):
198197
shutil.move(os.path.join(target_dir, update_dir, f), target_dir)
199198

200199
try:
201-
logger.info(
200+
logger.debug(
202201
f"删除临时更新文件: {zip_path}{os.path.join(target_dir, update_dir)}"
203202
)
204203
shutil.rmtree(os.path.join(target_dir, update_dir), onerror=on_error)
205204
os.remove(zip_path)
206205
except BaseException:
207-
logger.warn(
206+
logger.warning(
208207
f"删除更新文件失败,可以手动删除 {zip_path}{os.path.join(target_dir, update_dir)}"
209208
)
210209

astrbot/dashboard/routes/update.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def check_update(self):
4848
"version": f"v{VERSION}",
4949
"has_new_version": ret is not None,
5050
"dashboard_version": dv,
51-
"dashboard_has_new_version": dv != f"v{VERSION}",
51+
"dashboard_has_new_version": dv and dv != f"v{VERSION}",
5252
},
5353
).__dict__
5454
except Exception as e:
@@ -82,11 +82,12 @@ async def update_project(self):
8282
latest=latest, version=version, proxy=proxy
8383
)
8484

85-
if latest:
86-
try:
87-
await download_dashboard()
88-
except Exception as e:
89-
logger.error(f"下载管理面板文件失败: {e}。")
85+
try:
86+
await download_dashboard(
87+
latest=latest, version=version, proxy=proxy
88+
)
89+
except Exception as e:
90+
logger.error(f"下载管理面板文件失败: {e}。")
9091

9192
# pip 更新依赖
9293
logger.info("更新依赖中...")

dashboard/src/i18n/locales/en-US/core/header.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"description": "Versions marked as pre-release may contain unknown issues or bugs and are not recommended for production use. If you encounter any problems, please visit ",
3232
"issueLink": "GitHub Issues"
3333
},
34-
"tip": "💡 TIP: Switching to an older version or a specific version will not re-download the dashboard files, which may cause some data display errors. You can find the corresponding dashboard files dist.zip at",
35-
"tipLink": "here",
36-
"tipContinue": ", extract and replace the data/dist folder. Of course, the frontend source code is in the dashboard directory, you can also build it yourself using npm install and npm build.",
34+
"tip": "💡 TIP:",
35+
"tipLink": "",
36+
"tipContinue": "By default, the corresponding version of the WebUI files will be downloaded when switching versions. The WebUI code is located in the dashboard directory of the project, and you can use npm to build it yourself.",
3737
"dockerTip": "The `Update to Latest Version` button will try to update both the bot main program and the dashboard. If you are using Docker deployment, you can also re-pull the image or use",
3838
"dockerTipLink": "watchtower",
3939
"dockerTipContinue": "to automatically monitor and pull.",

dashboard/src/i18n/locales/zh-CN/core/header.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
"description": "标有预发布标签的版本可能存在未知问题或 Bug,不建议在生产环境使用。如发现问题,请提交至 ",
3232
"issueLink": "GitHub Issues"
3333
},
34-
"tip": "💡 TIP: 跳到旧版本或者切换到某个版本不会重新下载管理面板文件,这可能会造成部分数据显示错误。您可在",
35-
"tipLink": "此处",
36-
"tipContinue": "找到对应的面板文件 dist.zip,解压后替换 data/dist 文件夹即可。当然,前端源代码在 dashboard 目录下,你也可以自己使用 npm install 和 npm build 构建。",
34+
"tip": "💡 TIP: ",
35+
"tipContinue": "默认在切换版本时会下载对应版本的 WebUI 文件。WebUI 代码位于项目的 dashboard 目录,您可使用 npm 自行构建。",
3736
"dockerTip": "`更新到最新版本` 按钮会同时尝试更新机器人主程序和管理面板。如果您正在使用 Docker 部署,也可以重新拉取镜像或者使用",
3837
"dockerTipLink": "watchtower",
3938
"dockerTipContinue": "来自动监控拉取。",

dashboard/src/layouts/full/vertical-header/VerticalHeader.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ commonStore.getStartTime();
342342
</div>
343343

344344
<div class="mb-4 mt-4">
345-
<small>{{ t('core.header.updateDialog.tip') }} <a
346-
href="https://github.com/Soulter/AstrBot/releases">{{ t('core.header.updateDialog.tipLink') }}</a>
345+
<small>{{ t('core.header.updateDialog.tip') }}
347346
{{ t('core.header.updateDialog.tipContinue') }}</small>
348347
</div>
349348

@@ -383,7 +382,7 @@ commonStore.getStartTime();
383382
</div>
384383
</v-alert>
385384

386-
<v-data-table :headers="releasesHeader" :items="releases" item-key="name">
385+
<v-data-table :headers="releasesHeader" :items="releases" item-key="name" :items-per-page="5">
387386
<template v-slot:item.tag_name="{ item }: { item: { tag_name: string } }">
388387
<div class="d-flex align-center">
389388
<span>{{ item.tag_name }}</span>

0 commit comments

Comments
 (0)