From 5a245fd7132b5d4da13ee83bd0eadb91d41735b6 Mon Sep 17 00:00:00 2001 From: Kyomotoi <0w0@imki.moe> Date: Fri, 4 Nov 2022 10:20:26 +0800 Subject: =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E9=87=8D=E6=9E=84=E6=8F=92?= =?UTF-8?q?=E4=BB=B6:=20=E6=8E=A7=E5=88=B6=E5=8F=B0=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/console/driver/__init__.py | 48 +++++++++++---------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'ATRI/plugins/console/driver/__init__.py') diff --git a/ATRI/plugins/console/driver/__init__.py b/ATRI/plugins/console/driver/__init__.py index e5dfdc6..b6b9f89 100644 --- a/ATRI/plugins/console/driver/__init__.py +++ b/ATRI/plugins/console/driver/__init__.py @@ -5,32 +5,14 @@ from fastapi.middleware.cors import CORSMiddleware from ATRI import conf from ATRI.log import log -from ATRI.plugins.console.data_source import FRONTEND_DIR -from .view import ( - handle_auther, - handle_base_uri, - handle_control_service, - handle_edit_block, - handle_get_block_list, - handle_get_service_list, - handle_runtime_info, - handle_message_deal_info, -) +from .path import * +from .api import * -CONSOLE_API_URI = "/capi" # base point -CONSOLE_API_AUTH_URI = "/capi/auth" # 验证后台许可 -CONSOLE_API_RUNTIME_URI = "/capi/runtime" # 获取运行占用信息 -CONSOLE_API_MESSAGE_URI = "/capi/message" # 获取信息处理信息 +from ..data_source import FRONTEND_DIR -CONSOLE_API_SERVICE_LIST_URI = "/capi/service/list" # 获取服务列表 -CONSOLE_API_SERVICE_CONTROL_URI = "/capi/service/control" # 对服务作出修改 -CONSOLE_API_BLOCK_LIST_URI = "/capi/block/list" # 获取封禁列表 -CONSOLE_API_BLOCK_EDIT_URI = "/capi/block/edit" # 编辑封禁列表 - - -def register_routes(driver: Driver): +def register_driver(driver: Driver): app = driver.server_app origins = ["*"] @@ -42,16 +24,18 @@ def register_routes(driver: Driver): allow_headers=["Content-Type"], ) - app.get(CONSOLE_API_URI)(handle_base_uri) - app.get(CONSOLE_API_AUTH_URI)(handle_auther) - app.get(CONSOLE_API_RUNTIME_URI)(handle_runtime_info) - app.get(CONSOLE_API_MESSAGE_URI)(handle_message_deal_info) + app.get(CONSOLE_BASE_URL)(base_url) + + app.get(CONSOLE_AUTH_URL)(auth_info) + + app.websocket(CONSOLE_RUNTIME_INFO_URL)(runtime_info) + app.websocket(CONSOLE_MESSAGE_INFO_URL)(message_info) - app.get(CONSOLE_API_SERVICE_LIST_URI)(handle_get_service_list) - app.get(CONSOLE_API_SERVICE_CONTROL_URI)(handle_control_service) + app.get(CONSOLE_SERVICE_LIST_URL)(service_list) + app.get(CONSOLE_SERVICE_EDIT_URL)(edit_service) - app.get(CONSOLE_API_BLOCK_LIST_URI)(handle_get_block_list) - app.get(CONSOLE_API_BLOCK_EDIT_URI)(handle_edit_block) + app.get(CONSOLE_BLOCK_LIST_URL)(block_list_info) + app.get(CONSOLE_BLOCK_EDIT_URL)(edit_block_list) static_path = str(FRONTEND_DIR) app.mount( @@ -64,6 +48,6 @@ def register_routes(driver: Driver): def init_driver(): from ATRI import driver + register_driver(driver()) # type: ignore c_url = f"{conf.BotConfig.host}:{conf.BotConfig.port}" - log.info(f"控制台将运行于: http://{c_url} 对应API节点为: /capi") - register_routes(driver()) # type: ignore + log.success(f"控制台将运行于: http://{c_url} 对应API节点为: /capi") -- cgit v1.2.3