chore: rename src/ to server/

This commit is contained in:
CrescentLeaf
2025-08-30 14:43:45 +08:00
parent 5e756636a9
commit 5666bcba24
16 changed files with 2 additions and 2 deletions

43
server/api/ApiManager.ts Normal file
View File

@@ -0,0 +1,43 @@
import HttpServerLike from '../types/HttpServerLike.ts'
import UserApi from "./UserApi.ts"
import SocketIo from "socket.io"
import ApiCallbackMessage from "../types/ApiCallbackMessage.ts"
import EventCallbackFunction from "../types/EventCallbackFunction.ts"
export default class ApiManager {
static httpServer: HttpServerLike
static socketIoServer: SocketIo.Server
static event_listeners: { [key: string] : EventCallbackFunction } = {}
static apis_instance: {}
static initServer(httpServer: HttpServerLike, socketIoServer: SocketIo.Server) {
this.httpServer = httpServer
this.socketIoServer = socketIoServer
}
static getHttpServer() {
return this.httpServer
}
static getSocketIoServer() {
return this.socketIoServer
}
static initAllApis() {
this.apis_instance = {
user: new UserApi()
}
}
static addEventListener(name: string, func: EventCallbackFunction) {
this.event_listeners[name] = func
}
static initEvents() {
const io = this.socketIoServer
io.on('connection', (socket) => {
socket.on("The_White_Silk", (name: string, args: {}, callback: (ret: ApiCallbackMessage) => void) => {
if (name == null || args == null) return callback({
msg: "Invalid request.",
code: 400
})
return callback(this.event_listeners[name]?.(args))
})
})
}
}

13
server/api/BaseApi.ts Normal file
View File

@@ -0,0 +1,13 @@
import EventCallbackFunction from "../types/EventCallbackFunction.ts"
import ApiManager from "./ApiManager.ts";
export default abstract class BaseApi {
abstract getName(): string
constructor() {
this.onInit()
}
abstract onInit(): void
registerEvent(name: string, func: EventCallbackFunction) {
ApiManager.addEventListener(this.getName() + "." + name, func)
}
}

18
server/api/UserApi.ts Normal file
View File

@@ -0,0 +1,18 @@
import BaseApi from "./BaseApi.ts";
export default class UserApi extends BaseApi {
override getName(): string {
return "User"
}
override onInit(): void {
this.registerEvent("", () => {
return {
msg: "",
code: 200,
data: {
}
}
})
}
}