From e50a90a770605790198cca6db6129fcc18f35ed8 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 6 Sep 2025 14:34:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(wip):=20=E9=80=B2=E4=B8=80=E6=AD=A5?= =?UTF-8?q?=E5=AE=8C=E5=96=84=20UserAPI=20=E5=92=8C=E5=9F=BA=E9=A1=9E?= =?UTF-8?q?=E5=87=BD=E6=95=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/BaseApi.ts | 6 ++++++ server/api/UserApi.ts | 2 +- server/types/EventCallbackFunction.ts | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/api/BaseApi.ts b/server/api/BaseApi.ts index 51672fb..d3b591b 100644 --- a/server/api/BaseApi.ts +++ b/server/api/BaseApi.ts @@ -8,6 +8,12 @@ export default abstract class BaseApi { this.onInit() } abstract onInit(): void + checkArgsMissing(args: {}, names: []) { + for (const k of names) + if (!(k in args)) + return true + return false + } registerEvent(name: CallMethod, func: EventCallbackFunction) { if (!name.startsWith(this.getName() + ".")) throw Error("注冊的事件應該與接口集合命名空間相匹配: " + name) ApiManager.addEventListener(name, func) diff --git a/server/api/UserApi.ts b/server/api/UserApi.ts index 3cdd70b..d7d8afd 100644 --- a/server/api/UserApi.ts +++ b/server/api/UserApi.ts @@ -5,7 +5,7 @@ export default class UserApi extends BaseApi { return "User" } override onInit(): void { - this.registerEvent("User.auth", () => { + this.registerEvent("User.auth", (args) => { return { msg: "", code: 200, diff --git a/server/types/EventCallbackFunction.ts b/server/types/EventCallbackFunction.ts index 59b857c..a1e8f29 100644 --- a/server/types/EventCallbackFunction.ts +++ b/server/types/EventCallbackFunction.ts @@ -1,5 +1,5 @@ import ApiCallbackMessage from "../api/ApiCallbackMessage.ts" -type EventCallbackFunction = (args: {}) => ApiCallbackMessage +type EventCallbackFunction = (args: { [key: string]: unknown }) => ApiCallbackMessage export default EventCallbackFunction