mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-26 15:51:26 +00:00
🐛 fix cqhttp secret checking #289
This commit is contained in:
@ -72,7 +72,7 @@ class Bot(abc.ABC):
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
async def check_permission(cls, driver: "Driver", connection_type: str,
|
||||
headers: dict, body: Optional[dict]) -> str:
|
||||
headers: dict, body: Optional[bytes]) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
@ -83,7 +83,7 @@ class Bot(abc.ABC):
|
||||
* ``driver: Driver``: Driver 对象
|
||||
* ``connection_type: str``: 连接类型
|
||||
* ``headers: dict``: 请求头
|
||||
* ``body: Optional[dict]``: 请求数据,WebSocket 连接该部分为空
|
||||
* ``body: Optional[bytes]``: 请求数据,WebSocket 连接该部分为 None
|
||||
|
||||
:返回:
|
||||
|
||||
|
@ -16,7 +16,7 @@ from typing import List, Optional, Callable
|
||||
import uvicorn
|
||||
from pydantic import BaseSettings
|
||||
from fastapi.responses import Response
|
||||
from fastapi import Body, status, Request, FastAPI, HTTPException
|
||||
from fastapi import status, Request, FastAPI, HTTPException
|
||||
from starlette.websockets import WebSocketDisconnect, WebSocket as FastAPIWebSocket
|
||||
|
||||
from nonebot.log import logger
|
||||
@ -177,11 +177,11 @@ class Driver(BaseDriver):
|
||||
**kwargs)
|
||||
|
||||
@overrides(BaseDriver)
|
||||
async def _handle_http(self,
|
||||
adapter: str,
|
||||
request: Request,
|
||||
data: dict = Body(...)):
|
||||
if not isinstance(data, dict):
|
||||
async def _handle_http(self, adapter: str, request: Request):
|
||||
data = await request.body()
|
||||
data_dict = json.loads(data.decode())
|
||||
|
||||
if not isinstance(data_dict, dict):
|
||||
logger.warning("Data received is invalid")
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@ -208,7 +208,7 @@ class Driver(BaseDriver):
|
||||
|
||||
bot = BotClass("http", x_self_id)
|
||||
|
||||
asyncio.create_task(bot.handle_message(data))
|
||||
asyncio.create_task(bot.handle_message(data_dict))
|
||||
return Response("", 204)
|
||||
|
||||
@overrides(BaseDriver)
|
||||
|
Reference in New Issue
Block a user