From 316fd140bc279bb7e29bd78b528ebd95bef42114 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Mon, 8 Sep 2025 23:16:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20BaseApi=20=E5=85=A9=E5=80=8B=20Token=20?= =?UTF-8?q?=E6=AA=A2=E6=9F=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/BaseApi.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/api/BaseApi.ts b/server/api/BaseApi.ts index 7588c72..8d58903 100644 --- a/server/api/BaseApi.ts +++ b/server/api/BaseApi.ts @@ -1,6 +1,8 @@ import EventCallbackFunction from "../typedef/EventCallbackFunction.ts" import ApiManager from "./ApiManager.ts" import { CallMethod } from './ApiDeclare.ts' +import User from "../data/User.ts" +import Token from "./Token.ts" export default abstract class BaseApi { abstract getName(): string @@ -20,6 +22,16 @@ export default abstract class BaseApi { return true return false } + checkUserToken(user: User, token: Token) { + if (!this.checkToken(token)) return false + if (token.author != user.bean.id) return false + return true + } + checkToken(token: Token) { + if (token.expired_time < Date.now()) return false + if (!User.findById(token.author)) return false + return true + } registerEvent(name: CallMethod, func: EventCallbackFunction) { if (!name.startsWith(this.getName() + ".")) throw Error("注冊的事件應該與接口集合命名空間相匹配: " + name) ApiManager.addEventListener(name, func)