mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-06 04:10:02 +08:00
🎨 代码优化
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from fastapi import APIRouter, FastAPI
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi import APIRouter, FastAPI
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
@@ -32,4 +32,4 @@ async def init_public(app: FastAPI):
|
||||
name=f"public_{pathname}",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"初始化 web ui assets 失败 e: {e}", "Web UI assets")
|
||||
logger.error(f"初始化 web ui assets 失败", "Web UI assets", e=e)
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot.utils import run_sync
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
|
||||
from .config import (
|
||||
WEBUI_ASSETS_DOWNLOAD_URL,
|
||||
WEBUI_DATA_PATH,
|
||||
TMP_PATH,
|
||||
COMMAND_NAME,
|
||||
PUBLIC_PATH,
|
||||
)
|
||||
from .config import COMMAND_NAME, PUBLIC_PATH, TMP_PATH, WEBUI_ASSETS_DOWNLOAD_URL
|
||||
|
||||
|
||||
async def update_webui_assets():
|
||||
@@ -22,13 +17,8 @@ async def update_webui_assets():
|
||||
WEBUI_ASSETS_DOWNLOAD_URL, webui_assets_path, follow_redirects=True
|
||||
):
|
||||
logger.info("下载 webui_assets 成功...", COMMAND_NAME)
|
||||
else:
|
||||
logger.error("下载 webui_assets 失败...", COMMAND_NAME)
|
||||
|
||||
await _file_handle(webui_assets_path)
|
||||
|
||||
logger.info("更新 webui_assets 成功...", COMMAND_NAME)
|
||||
return True
|
||||
return await _file_handle(webui_assets_path)
|
||||
raise Exception("下载 webui_assets 失败", COMMAND_NAME)
|
||||
|
||||
|
||||
@run_sync
|
||||
@@ -39,8 +29,7 @@ def _file_handle(webui_assets_path: Path):
|
||||
tf.extractall(TMP_PATH)
|
||||
logger.debug("解压 webui_assets 成功...", COMMAND_NAME)
|
||||
else:
|
||||
logger.error("解压 webui_assets 失败...", COMMAND_NAME)
|
||||
return
|
||||
raise Exception("解压 webui_assets 失败,文件不存在...", COMMAND_NAME)
|
||||
download_file_path = (
|
||||
TMP_PATH / [x for x in os.listdir(TMP_PATH) if (TMP_PATH / x).is_dir()][0]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user