feat: 支持使用 /dashboard update 更新管理面板

This commit is contained in:
Soulter
2025-01-09 00:59:28 +08:00
parent 6b078a5731
commit d787a28c40
5 changed files with 38 additions and 21 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
如需修改配置,请在 `data/cmd_config.json` 中修改或者在管理面板中可视化修改。
"""
VERSION = "3.4.2"
VERSION = "3.4.3"
DB_PATH = "data/data_v3.db"
# 默认配置
+10
View File
@@ -5,6 +5,7 @@ import socket
import time
import aiohttp
import base64
import zipfile
from PIL import Image
@@ -97,6 +98,8 @@ async def download_file(url: str, path: str):
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=20) as resp:
if resp.status != 200:
raise Exception(f"下载文件失败: {resp.status}")
with open(path, 'wb') as f:
while True:
chunk = await resp.content.read(8192)
@@ -123,3 +126,10 @@ def get_local_ip_addresses():
finally:
s.close()
return ip
async def download_dashboard():
'''下载管理面板文件'''
dashboard_release_url = "https://astrbot-registry.soulter.top/download/astrbot-dashboard/latest/dist.zip"
await download_file(dashboard_release_url, "data/dashboard.zip")
with zipfile.ZipFile("data/dashboard.zip", "r") as z:
z.extractall("data")
-1
View File
@@ -18,7 +18,6 @@ class AstrBotDashboard():
self.core_lifecycle = core_lifecycle
self.config = core_lifecycle.astrbot_config
self.data_path = os.path.abspath(os.path.join(DATAPATH, "dist"))
logger.info(f"Dashboard data path: {self.data_path}")
self.app = Quart("dashboard", static_folder=self.data_path, static_url_path="/")
self.app.json.sort_keys = False
self.app.before_request(self.auth_middleware)
+14 -19
View File
@@ -7,6 +7,8 @@ import zipfile
from astrbot.dashboard import AstrBotDashBoardLifecycle
from astrbot.core import db_helper
from astrbot.core import logger, LogManager, LogBroker
from astrbot.core.config.default import VERSION
from astrbot.core.utils.io import download_dashboard
# add parent path to sys.path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -38,27 +40,20 @@ def check_env():
async def check_dashboard_files():
'''下载管理面板文件'''
if os.path.exists("data/dist"):
return
dashboard_release_url = "https://astrbot-registry.soulter.top/download/astrbot-dashboard/latest/dist.zip"
logger.info("开始下载管理面板文件...")
ok = False
async with aiohttp.ClientSession() as session:
async with session.get(dashboard_release_url) as resp:
if resp.status != 200:
logger.error(f"下载管理面板文件失败: {resp.status}")
else:
with open("data/dashboard.zip", "wb") as f:
f.write(await resp.read())
logger.info("管理面板文件下载完成。")
ok = True
if not ok:
logger.critical("下载管理面板文件失败")
if os.path.exists("data/dist/assets/version"):
with open("data/dist/assets/version", "r") as f:
if f.read() != VERSION:
logger.warning("检测到管理面板有更新。可以使用 /dashboard update 命令更新。")
return
# unzip
with zipfile.ZipFile("data/dashboard.zip", "r") as z:
z.extractall("data")
logger.info("开始下载管理面板文件...")
try:
await download_dashboard()
except Exception as e:
logger.critical(f"下载管理面板文件失败: {e}")
return
logger.info("管理面板下载完成。")
if __name__ == "__main__":
+13
View File
@@ -5,6 +5,7 @@ import astrbot.api.event.filter as filter
from astrbot.api.event import AstrMessageEvent, MessageEventResult
from astrbot.api import personalities, sp
from astrbot.api.provider import Personality, ProviderRequest
from astrbot.core.utils.io import download_dashboard
from typing import Union
@@ -44,6 +45,7 @@ class Main(star.Star):
/deop <admin_id>: 取消管理员
/wl <sid>: 添加会话白名单
/dwl <sid>: 删除会话白名单
/dashboard update: 更新管理面板
[大模型]
/provider: 查看、切换大模型提供商
@@ -342,6 +344,17 @@ UID: {user_id} 此 ID 可用于设置管理员。/op <UID> 授权管理员, /deo
message.set_result(
MessageEventResult().message(f"人格已设置。 \n人格信息: {ps}"))
@filter.command_group("dashboard")
@filter.permission_type(filter.PermissionType.ADMIN)
def dashboard(self):
pass
@dashboard.command("update")
async def update_dashboard(self, event: AstrMessageEvent):
yield event.plain_result("正在尝试更新管理面板...")
await download_dashboard()
yield event.plain_result("管理面板更新完成。")
@filter.on_llm_request()
async def decorate_llm_req(self, event: AstrMessageEvent, req: ProviderRequest):
provider = self.context.get_using_provider()