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 import GithubUtils
|
||||||
from zhenxun.utils.github_utils.models import RepoInfo
|
from zhenxun.utils.github_utils.models import RepoInfo
|
||||||
from zhenxun.utils.http_utils import AsyncHttpx
|
from zhenxun.utils.http_utils import AsyncHttpx
|
||||||
|
from zhenxun.utils.manager.resource_manager import (
|
||||||
|
DownloadResourceException,
|
||||||
|
ResourceManager,
|
||||||
|
)
|
||||||
from zhenxun.utils.platform import PlatformUtils
|
from zhenxun.utils.platform import PlatformUtils
|
||||||
|
|
||||||
from .config import (
|
from .config import (
|
||||||
@ -171,7 +175,7 @@ class UpdateManage:
|
|||||||
url = None
|
url = None
|
||||||
new_version = None
|
new_version = None
|
||||||
repo_info = GithubUtils.parse_github_url(DEFAULT_GITHUB_URL)
|
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
|
repo_info.branch = version_type
|
||||||
new_version = await cls.__get_version_from_repo(repo_info)
|
new_version = await cls.__get_version_from_repo(repo_info)
|
||||||
if new_version:
|
if new_version:
|
||||||
@ -203,8 +207,13 @@ class UpdateManage:
|
|||||||
if await AsyncHttpx.download_file(url, download_file, stream=True):
|
if await AsyncHttpx.download_file(url, download_file, stream=True):
|
||||||
logger.debug("下载真寻最新版文件完成...", "检查更新")
|
logger.debug("下载真寻最新版文件完成...", "检查更新")
|
||||||
await _file_handle(new_version)
|
await _file_handle(new_version)
|
||||||
|
result = "版本更新完成\n"
|
||||||
|
try:
|
||||||
|
await ResourceManager.init_resources(True)
|
||||||
|
except DownloadResourceException:
|
||||||
|
result += "资源下载失败..."
|
||||||
return (
|
return (
|
||||||
f"版本更新完成\n"
|
f"{result}\n"
|
||||||
f"版本: {cur_version} -> {new_version}\n"
|
f"版本: {cur_version} -> {new_version}\n"
|
||||||
"请重新启动真寻以完成更新!"
|
"请重新启动真寻以完成更新!"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -11,6 +11,10 @@ from zhenxun.utils.http_utils import AsyncHttpx
|
|||||||
CMD_STRING = "ResourceManager"
|
CMD_STRING = "ResourceManager"
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadResourceException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ResourceManager:
|
class ResourceManager:
|
||||||
GITHUB_URL = "https://github.com/zhenxun-org/zhenxun-bot-resources/tree/main"
|
GITHUB_URL = "https://github.com/zhenxun-org/zhenxun-bot-resources/tree/main"
|
||||||
|
|
||||||
@ -23,8 +27,8 @@ class ResourceManager:
|
|||||||
UNZIP_PATH = None
|
UNZIP_PATH = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def init_resources(cls):
|
async def init_resources(cls, force: bool = False):
|
||||||
if FONT_PATH.exists() and os.listdir(FONT_PATH):
|
if (FONT_PATH.exists() and os.listdir(FONT_PATH)) and not force:
|
||||||
return
|
return
|
||||||
if cls.TMP_PATH.exists():
|
if cls.TMP_PATH.exists():
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@ -66,7 +70,7 @@ class ResourceManager:
|
|||||||
url = await repo_info.get_archive_download_urls()
|
url = await repo_info.get_archive_download_urls()
|
||||||
logger.debug("开始下载resources资源包...", CMD_STRING)
|
logger.debug("开始下载resources资源包...", CMD_STRING)
|
||||||
if not await AsyncHttpx.download_file(url, cls.ZIP_FILE, stream=True):
|
if not await AsyncHttpx.download_file(url, cls.ZIP_FILE, stream=True):
|
||||||
raise Exception("下载resources资源包失败...")
|
raise DownloadResourceException("下载resources资源包失败...")
|
||||||
logger.debug("下载resources资源文件压缩包完成...", CMD_STRING)
|
logger.debug("下载resources资源文件压缩包完成...", CMD_STRING)
|
||||||
tf = zipfile.ZipFile(cls.ZIP_FILE)
|
tf = zipfile.ZipFile(cls.ZIP_FILE)
|
||||||
tf.extractall(cls.TMP_PATH)
|
tf.extractall(cls.TMP_PATH)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user