diff options
Diffstat (limited to 'ATRI/plugins/status/driver')
-rw-r--r-- | ATRI/plugins/status/driver/__init__.py | 41 | ||||
-rw-r--r-- | ATRI/plugins/status/driver/view.py | 39 |
2 files changed, 0 insertions, 80 deletions
diff --git a/ATRI/plugins/status/driver/__init__.py b/ATRI/plugins/status/driver/__init__.py deleted file mode 100644 index 199fb1e..0000000 --- a/ATRI/plugins/status/driver/__init__.py +++ /dev/null @@ -1,41 +0,0 @@ -from nonebot import get_driver -from nonebot.drivers.fastapi import Driver - -from fastapi.middleware.cors import CORSMiddleware - -from .view import ( - handle_auther, - handle_base_uri, - handle_runtime_info, - handle_message_deal_info, -) - - -CONSOLE_API_URI = "/capi" # base point -CONSOLE_API_AUTH_URI = "/capi/auth" # 验证后台许可 -CONSOLE_API_RUNTIME_URI = "/capi/runtime" # 获取运行占用信息 -CONSOLE_API_MESSAGE_URI = "/capi/message" -# CONSOLE_API_AUTH_COOKIES_URI = "/capi/auth/cookies" # 验证cookies - - -def register_routes(driver: Driver): - app = driver.server_app - - origins = ["*"] - app.add_middleware( - CORSMiddleware, - allow_origins=origins, - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], - ) - - app.get(CONSOLE_API_URI)(handle_base_uri) - app.get(CONSOLE_API_RUNTIME_URI)(handle_runtime_info) - app.get(CONSOLE_API_MESSAGE_URI)(handle_message_deal_info) - app.get(CONSOLE_API_AUTH_URI)(handle_auther) - - -def init(): - driver = get_driver() - register_routes(driver) # type: ignore diff --git a/ATRI/plugins/status/driver/view.py b/ATRI/plugins/status/driver/view.py deleted file mode 100644 index 5d8c56f..0000000 --- a/ATRI/plugins/status/driver/view.py +++ /dev/null @@ -1,39 +0,0 @@ -from ..data_source import Status -from ..listener import get_message_deal_info - - -def handle_base_uri(): - return {"status": 204, "msg": "This path just for console load."} - - -def handle_runtime_info(token: str): - auth, data = auth_token(token) - plat, bot = Status().get_status(True) - if auth: - return {"status": 200, "data": {"platform": plat, "bot": bot}} - else: - return data - - -def handle_message_deal_info(token: str): - auth, data = auth_token(token) - if auth: - return {"status": 200, "data": get_message_deal_info()} - else: - return data - - -def handle_auther(token: str): - auth, data = auth_token(token) - return data if auth else data - - -def auth_token(token: str) -> tuple: - auth_data: dict = Status().get_auth_info() - if not auth_data.get("token", None): - return False, {"status": 500, "msg": "This bot is not create auth data yet."} - _token = auth_data["token"] - if token != _token: - return False, {"status": 403, "msg": "Token error, please check again."} - else: - return True, {"status": 200, "msg": "OK"} |