進一步完善對外 API
This commit is contained in:
@@ -2,6 +2,7 @@ import BaseApi from './BaseApi.ts'
|
|||||||
import HttpServerLike from '../types/HttpServerLike.ts'
|
import HttpServerLike from '../types/HttpServerLike.ts'
|
||||||
import UserApi from "./UserApi.ts"
|
import UserApi from "./UserApi.ts"
|
||||||
import SocketIo from "socket.io"
|
import SocketIo from "socket.io"
|
||||||
|
import UnknownFunction from "../types/UnknownFunction.ts";
|
||||||
|
|
||||||
export default class ApiManager {
|
export default class ApiManager {
|
||||||
static httpServer: HttpServerLike
|
static httpServer: HttpServerLike
|
||||||
@@ -14,9 +15,22 @@ export default class ApiManager {
|
|||||||
static getHttpServer() {
|
static getHttpServer() {
|
||||||
return this.httpServer
|
return this.httpServer
|
||||||
}
|
}
|
||||||
|
static getSocketIoServer() {
|
||||||
|
return this.socketIoServer
|
||||||
|
}
|
||||||
static initAllApis() {
|
static initAllApis() {
|
||||||
this.apis_instance = {
|
this.apis_instance = {
|
||||||
user: new UserApi()
|
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({
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import UnknownFunction from '../types/UnknownFunction.ts'
|
import UnknownFunction from '../types/UnknownFunction.ts'
|
||||||
|
import ApiManager from "./ApiManager.ts";
|
||||||
|
|
||||||
export default abstract class BaseApi {
|
export default abstract class BaseApi {
|
||||||
abstract getName(): string
|
abstract getName(): string
|
||||||
@@ -7,6 +8,7 @@ export default abstract class BaseApi {
|
|||||||
}
|
}
|
||||||
abstract onInit(): void
|
abstract onInit(): void
|
||||||
registerEvent(name: string, func: UnknownFunction) {
|
registerEvent(name: string, func: UnknownFunction) {
|
||||||
|
const io = ApiManager.getSocketIoServer()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/types/ApiCallbackMessage.ts
Normal file
4
src/types/ApiCallbackMessage.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
type ApiCallbackMessage = {
|
||||||
|
msg: string,
|
||||||
|
code: 200 | 400 | 401 | 403 | 404 | 500 | 501
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user