diff --git a/astrbot/core/updator.py b/astrbot/core/updator.py index e76c6f032..439c05a52 100644 --- a/astrbot/core/updator.py +++ b/astrbot/core/updator.py @@ -56,9 +56,7 @@ class AstrBotUpdator(RepoZipUpdator): try: if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli if os.name == "nt": - args = [ - f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:] - ] + args = [f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:]] else: args = sys.argv[1:] os.execl(sys.executable, py, "-m", "astrbot.cli.__main__", *args) @@ -68,9 +66,13 @@ class AstrBotUpdator(RepoZipUpdator): logger.error(f"重启失败({py}, {e}),请尝试手动重启。") raise e - async def check_update(self, url: str, current_version: str) -> ReleaseInfo: + async def check_update( + self, url: str, current_version: str, consider_prerelease: bool = True + ) -> ReleaseInfo: """检查更新""" - return await super().check_update(self.ASTRBOT_RELEASE_API, VERSION) + return await super().check_update( + self.ASTRBOT_RELEASE_API, VERSION, consider_prerelease + ) async def get_releases(self) -> list: return await self.fetch_release_info(self.ASTRBOT_RELEASE_API) diff --git a/astrbot/core/zip_updator.py b/astrbot/core/zip_updator.py index c72965e67..7e5f3bfbb 100644 --- a/astrbot/core/zip_updator.py +++ b/astrbot/core/zip_updator.py @@ -107,16 +107,38 @@ class RepoZipUpdator: """Semver 版本比较""" return VersionComparator.compare_version(v1, v2) - async def check_update(self, url: str, current_version: str) -> ReleaseInfo | None: + async def check_update( + self, url: str, current_version: str, consider_prerelease: bool = True + ) -> ReleaseInfo | None: update_data = await self.fetch_release_info(url) - tag_name = update_data[0]["tag_name"] + + sel_release_data = None + if consider_prerelease: + tag_name = update_data[0]["tag_name"] + sel_release_data = update_data[0] + else: + for data in update_data: + # 跳过带有 alpha、beta 等预发布标签的版本 + if re.search( + r"[\-_.]?(alpha|beta|rc|dev)[\-_.]?\d*$", + data["tag_name"], + re.IGNORECASE, + ): + continue + tag_name = data["tag_name"] + sel_release_data = data + break + + if not sel_release_data or not tag_name: + logger.error("未找到合适的发布版本") + return None if self.compare_version(current_version, tag_name) >= 0: return None return ReleaseInfo( version=tag_name, - published_at=update_data[0]["published_at"], - body=update_data[0]["body"], + published_at=sel_release_data["published_at"], + body=f"{tag_name}\n\n{sel_release_data['body']}", ) async def download_from_repo_url(self, target_path: str, repo_url: str, proxy=""): diff --git a/astrbot/dashboard/routes/update.py b/astrbot/dashboard/routes/update.py index b9519a1cd..9a50a5ce2 100644 --- a/astrbot/dashboard/routes/update.py +++ b/astrbot/dashboard/routes/update.py @@ -40,7 +40,7 @@ class UpdateRoute(Route): .__dict__ ) else: - ret = await self.astrbot_updator.check_update(None, None) + ret = await self.astrbot_updator.check_update(None, None, False) return Response( status="success", message=str(ret) if ret is not None else "已经是最新版本了。", @@ -82,11 +82,10 @@ class UpdateRoute(Route): latest=latest, version=version, proxy=proxy ) - # 更新 WebUI 操作放在启动时,以下载指定版本的 WebUI 构建文件 - # try: - # await download_dashboard(latest=latest, version=version, proxy=proxy) - # except Exception as e: - # logger.error(f"下载管理面板文件失败: {e}。") + try: + await download_dashboard(latest=latest, version=version, proxy=proxy) + except Exception as e: + logger.error(f"下载管理面板文件失败: {e}。") # pip 更新依赖 logger.info("更新依赖中...") diff --git a/dashboard/src/i18n/locales/en-US/core/header.json b/dashboard/src/i18n/locales/en-US/core/header.json index ee0949988..cfc76fe02 100644 --- a/dashboard/src/i18n/locales/en-US/core/header.json +++ b/dashboard/src/i18n/locales/en-US/core/header.json @@ -34,7 +34,7 @@ "tip": "💡 TIP:", "tipLink": "", "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.", - "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", + "dockerTip": "When switching versions, it 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", "dockerTipLink": "watchtower", "dockerTipContinue": "to automatically monitor and pull.", "table": { diff --git a/dashboard/src/i18n/locales/zh-CN/core/header.json b/dashboard/src/i18n/locales/zh-CN/core/header.json index 611ad31c3..54738b8d6 100644 --- a/dashboard/src/i18n/locales/zh-CN/core/header.json +++ b/dashboard/src/i18n/locales/zh-CN/core/header.json @@ -33,7 +33,7 @@ }, "tip": "💡 TIP: ", "tipContinue": "默认在切换版本时会下载对应版本的 WebUI 文件。WebUI 代码位于项目的 dashboard 目录,您可使用 npm 自行构建。", - "dockerTip": "`更新到最新版本` 按钮会同时尝试更新机器人主程序和管理面板。如果您正在使用 Docker 部署,也可以重新拉取镜像或者使用", + "dockerTip": "切换版本时,会同时尝试更新机器人主程序和管理面板。如果您正在使用 Docker 部署,也可以重新拉取镜像或者使用", "dockerTipLink": "watchtower", "dockerTipContinue": "来自动监控拉取。", "table": { diff --git a/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue b/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue index 44163c7b3..476862485 100644 --- a/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue +++ b/dashboard/src/layouts/full/vertical-header/VerticalHeader.vue @@ -377,10 +377,6 @@ commonStore.getStartTime(); - - {{ t('core.header.updateDialog.updateToLatest') }} -
{{ t('core.header.updateDialog.dockerTip') }} {{ t('core.header.updateDialog.dockerTipLink') }} {{ t('core.header.updateDialog.dockerTipContinue') }} diff --git a/main.py b/main.py index 113f004b2..b453d4c34 100644 --- a/main.py +++ b/main.py @@ -44,12 +44,12 @@ async def check_dashboard_files(): if v is not None: # has file if v == f"v{VERSION}": - logger.info("管理面板文件已是最新。") - return + logger.info("WebUI 版本已是最新。") else: logger.warning( - f"检测到管理面板有更新,准备更新至指定版本 {VERSION} (当前 WebUI 版本: {v})" + f"检测到 WebUI 版本 ({v}) 与当前 AstrBot 版本 (v{VERSION}) 不符。" ) + return logger.info( "开始下载管理面板文件...高峰期(晚上)可能导致较慢的速度。如多次下载失败,请前往 https://github.com/Soulter/AstrBot/releases/latest 下载 dist.zip,并将其中的 dist 文件夹解压至 data 目录下。"