mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🚀 优化版本更新逻辑,增加资源下载异常处理
This commit is contained in:
parent
3071daf302
commit
603ad5bc8b
@ -11,6 +11,10 @@ from zhenxun.services.log import logger
|
||||
from zhenxun.utils.github_utils import GithubUtils
|
||||
from zhenxun.utils.github_utils.models import RepoInfo
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.utils.manager.resource_manager import (
|
||||
DownloadResourceException,
|
||||
ResourceManager,
|
||||
)
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
from .config import (
|
||||
@ -171,7 +175,7 @@ class UpdateManage:
|
||||
url = None
|
||||
new_version = None
|
||||
repo_info = GithubUtils.parse_github_url(DEFAULT_GITHUB_URL)
|
||||
if version_type in {"dev", "main"}:
|
||||
if version_type in {"main"}:
|
||||
repo_info.branch = version_type
|
||||
new_version = await cls.__get_version_from_repo(repo_info)
|
||||
if new_version:
|
||||
@ -203,8 +207,13 @@ class UpdateManage:
|
||||
if await AsyncHttpx.download_file(url, download_file, stream=True):
|
||||
logger.debug("下载真寻最新版文件完成...", "检查更新")
|
||||
await _file_handle(new_version)
|
||||
result = "版本更新完成\n"
|
||||
try:
|
||||
await ResourceManager.init_resources(True)
|
||||
except DownloadResourceException:
|
||||
result += "资源下载失败..."
|
||||
return (
|
||||
f"版本更新完成\n"
|
||||
f"{result}\n"
|
||||
f"版本: {cur_version} -> {new_version}\n"
|
||||
"请重新启动真寻以完成更新!"
|
||||
)
|
||||
|
||||
@ -11,6 +11,10 @@ from zhenxun.utils.http_utils import AsyncHttpx
|
||||
CMD_STRING = "ResourceManager"
|
||||
|
||||
|
||||
class DownloadResourceException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ResourceManager:
|
||||
GITHUB_URL = "https://github.com/zhenxun-org/zhenxun-bot-resources/tree/main"
|
||||
|
||||
@ -23,8 +27,8 @@ class ResourceManager:
|
||||
UNZIP_PATH = None
|
||||
|
||||
@classmethod
|
||||
async def init_resources(cls):
|
||||
if FONT_PATH.exists() and os.listdir(FONT_PATH):
|
||||
async def init_resources(cls, force: bool = False):
|
||||
if (FONT_PATH.exists() and os.listdir(FONT_PATH)) and not force:
|
||||
return
|
||||
if cls.TMP_PATH.exists():
|
||||
logger.debug(
|
||||
@ -66,7 +70,7 @@ class ResourceManager:
|
||||
url = await repo_info.get_archive_download_urls()
|
||||
logger.debug("开始下载resources资源包...", CMD_STRING)
|
||||
if not await AsyncHttpx.download_file(url, cls.ZIP_FILE, stream=True):
|
||||
raise Exception("下载resources资源包失败...")
|
||||
raise DownloadResourceException("下载resources资源包失败...")
|
||||
logger.debug("下载resources资源文件压缩包完成...", CMD_STRING)
|
||||
tf = zipfile.ZipFile(cls.ZIP_FILE)
|
||||
tf.extractall(cls.TMP_PATH)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user