From 76cafea7d4a8c0301a781f540bd0b678673c17aa Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Thu, 6 Feb 2025 11:03:49 +0800 Subject: [PATCH] =?UTF-8?q?:adhesive=5Fbandage:=20=E4=BC=98=E5=8C=96webapi?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web_ui/api/tabs/dashboard/data_source.py | 14 ++++++++++---- .../web_ui/api/tabs/main/data_source.py | 17 ++++++++++++----- .../web_ui/api/tabs/system/__init__.py | 1 + zhenxun/services/cache.py | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py b/zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py index 243dafc2..4ee6e85a 100644 --- a/zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py +++ b/zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py @@ -10,6 +10,7 @@ from tortoise.functions import Count from zhenxun.models.bot_connect_log import BotConnectLog from zhenxun.models.chat_history import ChatHistory from zhenxun.models.statistics import Statistics +from zhenxun.services.log import logger from zhenxun.utils.platform import PlatformUtils from ....base_model import BaseResultModel, QueryModel @@ -51,10 +52,15 @@ class ApiDataSource: bot_info = BotInfo( self_id=bot.self_id, nickname=nickname, ava_url=ava_url, platform=platform ) - group_list, _ = await PlatformUtils.get_group_list(bot, True) - friend_list, _ = await PlatformUtils.get_friend_list(bot) - bot_info.group_count = len(group_list) - bot_info.friend_count = len(friend_list) + try: + group_list, _ = await PlatformUtils.get_group_list(bot, True) + friend_list, _ = await PlatformUtils.get_friend_list(bot) + bot_info.group_count = len(group_list) + bot_info.friend_count = len(friend_list) + except Exception as e: + logger.warning("获取bot好友/群组数量失败...", "WebUi", e=e) + bot_info.group_count = 0 + bot_info.friend_count = 0 bot_info.day_call = await Statistics.filter( create_time__gte=now - timedelta(hours=now.hour, minutes=now.minute), bot_id=bot.self_id, diff --git a/zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py b/zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py index 79bbc5c0..2f3ca61b 100644 --- a/zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py +++ b/zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py @@ -110,11 +110,18 @@ class ApiDataSource: create_time__gte=now - timedelta(hours=now.hour), ).count() # 群聊数量 - select_bot.group_count = len(await PlatformUtils.get_group_list(select_bot.bot)) - # 好友数量 - select_bot.friend_count = len( - await PlatformUtils.get_friend_list(select_bot.bot) - ) + try: + select_bot.group_count = len( + (await PlatformUtils.get_group_list(select_bot.bot, True))[0] + ) + # 好友数量 + select_bot.friend_count = len( + (await PlatformUtils.get_friend_list(select_bot.bot))[0] + ) + except Exception as e: + logger.warning("获取bot好友/群组数量失败...", "WebUi", e=e) + select_bot.group_count = 0 + select_bot.friend_count = 0 select_bot.status = await BotConsole.get_bot_status(select_bot.self_id) # 连接时间 select_bot.connect_time = bot_live.get(select_bot.self_id) or 0 diff --git a/zhenxun/builtin_plugins/web_ui/api/tabs/system/__init__.py b/zhenxun/builtin_plugins/web_ui/api/tabs/system/__init__.py index 6e2aeeb4..673e058a 100644 --- a/zhenxun/builtin_plugins/web_ui/api/tabs/system/__init__.py +++ b/zhenxun/builtin_plugins/web_ui/api/tabs/system/__init__.py @@ -38,6 +38,7 @@ async def _(path: str | None = None) -> Result[list[DirFile]]: parent=path, ) ) + sorted(data_list, key=lambda f: f.name) return Result.ok(data_list) diff --git a/zhenxun/services/cache.py b/zhenxun/services/cache.py index dccbcff4..7170bef1 100644 --- a/zhenxun/services/cache.py +++ b/zhenxun/services/cache.py @@ -42,7 +42,7 @@ class CacheData(BaseModel): """缓存数据""" expire: int """缓存过期时间""" - reload_time = time.time() + reload_time: float = time.time() """更新时间""" reload_count: int = 0 """更新次数"""