進一步完善對外 API

This commit is contained in:
CrescentLeaf
2025-08-29 23:43:59 +08:00
parent 7bf5921298
commit d2007fbdcc
3 changed files with 20 additions and 0 deletions

View File

@@ -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({
})
})
})
}
}

View File

@@ -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()
}
}

View File

@@ -0,0 +1,4 @@
type ApiCallbackMessage = {
msg: string,
code: 200 | 400 | 401 | 403 | 404 | 500 | 501
}