mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-03 02:30:01 +08:00
@@ -10,10 +10,10 @@ from nonebot.utils import run_sync
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
from zhenxun.utils.github_utils.models import RepoInfo
|
||||
from zhenxun.utils.github_utils import parse_github_url
|
||||
|
||||
from .config import (
|
||||
DEV_URL,
|
||||
MAIN_URL,
|
||||
TMP_PATH,
|
||||
BASE_PATH,
|
||||
BACKUP_PATH,
|
||||
@@ -25,6 +25,7 @@ from .config import (
|
||||
BASE_PATH_STRING,
|
||||
DOWNLOAD_GZ_FILE,
|
||||
DOWNLOAD_ZIP_FILE,
|
||||
DEFAULT_GITHUB_URL,
|
||||
PYPROJECT_LOCK_FILE,
|
||||
REQ_TXT_FILE_STRING,
|
||||
PYPROJECT_FILE_STRING,
|
||||
@@ -169,23 +170,19 @@ class UpdateManage:
|
||||
cur_version = cls.__get_version()
|
||||
url = None
|
||||
new_version = None
|
||||
if version_type == "dev":
|
||||
url = DEV_URL
|
||||
new_version = await cls.__get_version_from_branch("dev")
|
||||
if new_version:
|
||||
new_version = new_version.split(":")[-1].strip()
|
||||
elif version_type == "main":
|
||||
url = MAIN_URL
|
||||
new_version = await cls.__get_version_from_branch("main")
|
||||
repo_info = parse_github_url(DEFAULT_GITHUB_URL)
|
||||
if version_type in {"dev", "main"}:
|
||||
repo_info.branch = version_type
|
||||
new_version = await cls.__get_version_from_repo(repo_info)
|
||||
if new_version:
|
||||
new_version = new_version.split(":")[-1].strip()
|
||||
url = await repo_info.get_archive_download_url()
|
||||
elif version_type == "release":
|
||||
data = await cls.__get_latest_data()
|
||||
if not data:
|
||||
return "获取更新版本失败..."
|
||||
url = data.get("tarball_url")
|
||||
new_version = data.get("name")
|
||||
url = (await AsyncHttpx.get(url)).headers.get("Location") # type: ignore
|
||||
new_version = data.get("name", "")
|
||||
url = await repo_info.get_release_source_download_url_tgz(new_version)
|
||||
if not url:
|
||||
return "获取版本下载链接失败..."
|
||||
if TMP_PATH.exists():
|
||||
@@ -247,7 +244,7 @@ class UpdateManage:
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
async def __get_version_from_branch(cls, branch: str) -> str:
|
||||
async def __get_version_from_repo(cls, repo_info: RepoInfo) -> str:
|
||||
"""从指定分支获取版本号
|
||||
|
||||
参数:
|
||||
@@ -256,11 +253,11 @@ class UpdateManage:
|
||||
返回:
|
||||
str: 版本号
|
||||
"""
|
||||
version_url = f"https://raw.githubusercontent.com/HibiKier/zhenxun_bot/{branch}/__version__"
|
||||
version_url = await repo_info.get_raw_download_url(path="__version__")
|
||||
try:
|
||||
res = await AsyncHttpx.get(version_url)
|
||||
if res.status_code == 200:
|
||||
return res.text.strip()
|
||||
except Exception as e:
|
||||
logger.error(f"获取 {branch} 分支版本失败", e=e)
|
||||
logger.error(f"获取 {repo_info.branch} 分支版本失败", e=e)
|
||||
return "未知版本"
|
||||
|
||||
Reference in New Issue
Block a user