🩹 优化webapi返回数据

This commit is contained in:
HibiKier 2025-02-06 11:03:49 +08:00
parent f80e541047
commit 76cafea7d4
4 changed files with 24 additions and 10 deletions

View File

@ -10,6 +10,7 @@ from tortoise.functions import Count
from zhenxun.models.bot_connect_log import BotConnectLog from zhenxun.models.bot_connect_log import BotConnectLog
from zhenxun.models.chat_history import ChatHistory from zhenxun.models.chat_history import ChatHistory
from zhenxun.models.statistics import Statistics from zhenxun.models.statistics import Statistics
from zhenxun.services.log import logger
from zhenxun.utils.platform import PlatformUtils from zhenxun.utils.platform import PlatformUtils
from ....base_model import BaseResultModel, QueryModel from ....base_model import BaseResultModel, QueryModel
@ -51,10 +52,15 @@ class ApiDataSource:
bot_info = BotInfo( bot_info = BotInfo(
self_id=bot.self_id, nickname=nickname, ava_url=ava_url, platform=platform self_id=bot.self_id, nickname=nickname, ava_url=ava_url, platform=platform
) )
group_list, _ = await PlatformUtils.get_group_list(bot, True) try:
friend_list, _ = await PlatformUtils.get_friend_list(bot) group_list, _ = await PlatformUtils.get_group_list(bot, True)
bot_info.group_count = len(group_list) friend_list, _ = await PlatformUtils.get_friend_list(bot)
bot_info.friend_count = len(friend_list) 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( bot_info.day_call = await Statistics.filter(
create_time__gte=now - timedelta(hours=now.hour, minutes=now.minute), create_time__gte=now - timedelta(hours=now.hour, minutes=now.minute),
bot_id=bot.self_id, bot_id=bot.self_id,

View File

@ -110,11 +110,18 @@ class ApiDataSource:
create_time__gte=now - timedelta(hours=now.hour), create_time__gte=now - timedelta(hours=now.hour),
).count() ).count()
# 群聊数量 # 群聊数量
select_bot.group_count = len(await PlatformUtils.get_group_list(select_bot.bot)) try:
# 好友数量 select_bot.group_count = len(
select_bot.friend_count = len( (await PlatformUtils.get_group_list(select_bot.bot, True))[0]
await PlatformUtils.get_friend_list(select_bot.bot) )
) # 好友数量
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.status = await BotConsole.get_bot_status(select_bot.self_id)
# 连接时间 # 连接时间
select_bot.connect_time = bot_live.get(select_bot.self_id) or 0 select_bot.connect_time = bot_live.get(select_bot.self_id) or 0

View File

@ -38,6 +38,7 @@ async def _(path: str | None = None) -> Result[list[DirFile]]:
parent=path, parent=path,
) )
) )
sorted(data_list, key=lambda f: f.name)
return Result.ok(data_list) return Result.ok(data_list)

View File

@ -42,7 +42,7 @@ class CacheData(BaseModel):
"""缓存数据""" """缓存数据"""
expire: int expire: int
"""缓存过期时间""" """缓存过期时间"""
reload_time = time.time() reload_time: float = time.time()
"""更新时间""" """更新时间"""
reload_count: int = 0 reload_count: int = 0
"""更新次数""" """更新次数"""