From 7042d94213532191a0c72d34d7c85193184c079f Mon Sep 17 00:00:00 2001 From: Kyomotoi Date: Wed, 4 May 2022 16:07:18 +0800 Subject: =?UTF-8?q?=E2=9C=A8=20=E4=B8=BA=E5=89=8D=E7=AB=AF=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=89=93=E5=9F=BA=E7=A1=80,=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=8F=8AAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/status/driver/__init__.py | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ATRI/plugins/status/driver/__init__.py (limited to 'ATRI/plugins/status/driver/__init__.py') diff --git a/ATRI/plugins/status/driver/__init__.py b/ATRI/plugins/status/driver/__init__.py new file mode 100644 index 0000000..199fb1e --- /dev/null +++ b/ATRI/plugins/status/driver/__init__.py @@ -0,0 +1,41 @@ +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 -- cgit v1.2.3