From d2007fbdccc9a57d6225bec13af676edc39744bf Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Fri, 29 Aug 2025 23:43:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=B2=E4=B8=80=E6=AD=A5=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=B0=8D=E5=A4=96=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ApiManager.ts | 14 ++++++++++++++ src/api/BaseApi.ts | 2 ++ src/types/ApiCallbackMessage.ts | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 src/types/ApiCallbackMessage.ts diff --git a/src/api/ApiManager.ts b/src/api/ApiManager.ts index d1d9c0a..7c753d7 100644 --- a/src/api/ApiManager.ts +++ b/src/api/ApiManager.ts @@ -2,6 +2,7 @@ import BaseApi from './BaseApi.ts' import HttpServerLike from '../types/HttpServerLike.ts' import UserApi from "./UserApi.ts" import SocketIo from "socket.io" +import UnknownFunction from "../types/UnknownFunction.ts"; export default class ApiManager { static httpServer: HttpServerLike @@ -14,9 +15,22 @@ export default class ApiManager { static getHttpServer() { return this.httpServer } + static getSocketIoServer() { + return this.socketIoServer + } static initAllApis() { this.apis_instance = { user: new UserApi() } } + static initEvents() { + const io = this.socketIoServer + io.on('connection', (socket) => { + socket.on("The_White_Silk", (name: string, args: {}, callback: UnknownFunction) => { + if (name == null || args == null) return callback({ + + }) + }) + }) + } } diff --git a/src/api/BaseApi.ts b/src/api/BaseApi.ts index 6a36ab0..2d83ca8 100644 --- a/src/api/BaseApi.ts +++ b/src/api/BaseApi.ts @@ -1,4 +1,5 @@ import UnknownFunction from '../types/UnknownFunction.ts' +import ApiManager from "./ApiManager.ts"; export default abstract class BaseApi { abstract getName(): string @@ -7,6 +8,7 @@ export default abstract class BaseApi { } abstract onInit(): void registerEvent(name: string, func: UnknownFunction) { + const io = ApiManager.getSocketIoServer() } } diff --git a/src/types/ApiCallbackMessage.ts b/src/types/ApiCallbackMessage.ts new file mode 100644 index 0000000..565c431 --- /dev/null +++ b/src/types/ApiCallbackMessage.ts @@ -0,0 +1,4 @@ +type ApiCallbackMessage = { + msg: string, + code: 200 | 400 | 401 | 403 | 404 | 500 | 501 +} \ No newline at end of file