Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions astrbot/core/conversation_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ async def _trigger_session_deleted(self, unified_msg_origin: str) -> None:

def _convert_conv_from_v2_to_v1(self, conv_v2: ConversationV2) -> Conversation:
"""将 ConversationV2 对象转换为 Conversation 对象"""
created_at = int(conv_v2.created_at.timestamp())
updated_at = int(conv_v2.updated_at.timestamp())
from datetime import timezone
Comment thread
WintryWind7 marked this conversation as resolved.
Outdated
created_at = int(conv_v2.created_at.replace(tzinfo=timezone.utc).timestamp()) if conv_v2.created_at else 0
updated_at = int(conv_v2.updated_at.replace(tzinfo=timezone.utc).timestamp()) if conv_v2.updated_at else 0
return Conversation(
platform_id=conv_v2.platform_id,
user_id=conv_v2.user_id,
Expand Down
6 changes: 3 additions & 3 deletions astrbot/dashboard/routes/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ async def stream():
"type": "message_saved",
"data": {
"id": saved_record.id,
"created_at": saved_record.created_at.astimezone().isoformat(),
"created_at": saved_record.created_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
WintryWind7 marked this conversation as resolved.
Outdated
},
}
try:
Expand Down Expand Up @@ -718,8 +718,8 @@ async def get_sessions(self):
"creator": session.creator,
"display_name": session.display_name,
"is_group": session.is_group,
"created_at": session.created_at.astimezone().isoformat(),
"updated_at": session.updated_at.astimezone().isoformat(),
"created_at": session.created_at.replace(tzinfo=timezone.utc).isoformat(),
"updated_at": session.updated_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
WintryWind7 marked this conversation as resolved.
Outdated
}
)

Expand Down
16 changes: 8 additions & 8 deletions astrbot/dashboard/routes/chatui_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async def create_project(self):
"title": project.title,
"emoji": project.emoji,
"description": project.description,
"created_at": project.created_at.astimezone().isoformat(),
"updated_at": project.updated_at.astimezone().isoformat(),
"created_at": project.created_at.replace(tzinfo=timezone.utc).isoformat(),
"updated_at": project.updated_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
zouyonghe marked this conversation as resolved.
Outdated
}
)
.__dict__
Expand All @@ -70,8 +70,8 @@ async def list_projects(self):
"title": project.title,
"emoji": project.emoji,
"description": project.description,
"created_at": project.created_at.astimezone().isoformat(),
"updated_at": project.updated_at.astimezone().isoformat(),
"created_at": project.created_at.replace(tzinfo=timezone.utc).isoformat(),
"updated_at": project.updated_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
WintryWind7 marked this conversation as resolved.
Outdated
}
for project in projects
]
Expand Down Expand Up @@ -102,8 +102,8 @@ async def get_project(self):
"title": project.title,
"emoji": project.emoji,
"description": project.description,
"created_at": project.created_at.astimezone().isoformat(),
"updated_at": project.updated_at.astimezone().isoformat(),
"created_at": project.created_at.replace(tzinfo=timezone.utc).isoformat(),
"updated_at": project.updated_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
zouyonghe marked this conversation as resolved.
Outdated
}
)
.__dict__
Expand Down Expand Up @@ -236,8 +236,8 @@ async def get_project_sessions(self):
"creator": session.creator,
"display_name": session.display_name,
"is_group": session.is_group,
"created_at": session.created_at.astimezone().isoformat(),
"updated_at": session.updated_at.astimezone().isoformat(),
"created_at": session.created_at.replace(tzinfo=timezone.utc).isoformat(),
"updated_at": session.updated_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
zouyonghe marked this conversation as resolved.
Outdated
}
for session in sessions
]
Expand Down
2 changes: 1 addition & 1 deletion astrbot/dashboard/routes/live_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ async def _handle_chat_message(
"type": "message_saved",
"data": {
"id": saved_record.id,
"created_at": saved_record.created_at.astimezone().isoformat(),
"created_at": saved_record.created_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
WintryWind7 marked this conversation as resolved.
Outdated
},
},
)
Expand Down
6 changes: 3 additions & 3 deletions astrbot/dashboard/routes/open_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ async def _handle_chat_ws_send(self, post_data: dict) -> None:
"type": "message_saved",
"data": {
"id": saved_record.id,
"created_at": saved_record.created_at.astimezone().isoformat(),
"created_at": saved_record.created_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
WintryWind7 marked this conversation as resolved.
Outdated
},
"session_id": session_id,
}
Expand Down Expand Up @@ -579,8 +579,8 @@ async def get_chat_sessions(self):
"creator": session.creator,
"display_name": session.display_name,
"is_group": session.is_group,
"created_at": session.created_at.astimezone().isoformat(),
"updated_at": session.updated_at.astimezone().isoformat(),
"created_at": session.created_at.replace(tzinfo=timezone.utc).isoformat(),
"updated_at": session.updated_at.replace(tzinfo=timezone.utc).isoformat(),
Comment thread
WintryWind7 marked this conversation as resolved.
Outdated
}
)

Expand Down
14 changes: 13 additions & 1 deletion astrbot/dashboard/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,19 @@ def __init__(
self.app.config["MAX_CONTENT_LENGTH"] = (
128 * 1024 * 1024
) # 将 Flask 允许的最大上传文件体大小设置为 128 MB
cast(DefaultJSONProvider, self.app.json).sort_keys = False

from datetime import datetime, timezone
class AstrBotJSONProvider(DefaultJSONProvider):
def default(self, obj):
if isinstance(obj, datetime):
if obj.tzinfo is None:
# 默认为 UTC
return obj.replace(tzinfo=timezone.utc).isoformat()
return obj.isoformat()
return super().default(obj)
Comment thread
zouyonghe marked this conversation as resolved.
Outdated

self.app.json = AstrBotJSONProvider(self.app)
self.app.json.sort_keys = False
self.app.before_request(self.auth_middleware)
# token 用于验证请求
logging.getLogger(self.app.name).removeHandler(default_handler)
Expand Down