修复缺少safe_decode_json
This commit is contained in:
@@ -48,6 +48,18 @@ class Room:
|
||||
'created_at': self.created_at.isoformat()
|
||||
}
|
||||
|
||||
def safe_decode_json(raw_body: bytes) -> Dict[Any, Any]:
|
||||
"""
|
||||
尝试用 UTF-8 解码,失败则尝试 GB18030(兼容 GBK/GB2312)
|
||||
"""
|
||||
for encoding in ['utf-8', 'gb18030', 'latin1']:
|
||||
try:
|
||||
text = raw_body.decode(encoding)
|
||||
return json.loads(text)
|
||||
except (UnicodeDecodeError, json.JSONDecodeError):
|
||||
continue
|
||||
raise ValueError("无法解码请求体为有效 JSON")
|
||||
|
||||
def get_frontend_to_client_queue(room_id: str) -> List[Dict[str, Any]]:
|
||||
if room_id not in frontend_to_client_queues:
|
||||
frontend_to_client_queues[room_id] = []
|
||||
|
||||
Reference in New Issue
Block a user