chore: 將令牌檢測函數移動到 TokenManager

* 這樣才叫 TokenManager 嘛X
This commit is contained in:
CrescentLeaf
2025-09-25 14:18:50 +08:00
parent b6be09ef7c
commit 692eb3d2a3
2 changed files with 13 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ import ApiManager from "./ApiManager.ts"
import { CallMethod, ClientEvent } from './ApiDeclare.ts'
import User from "../data/User.ts"
import Token from "./Token.ts"
import TokenManager from './TokenManager.ts'
import * as SocketIo from "socket.io"
export default abstract class BaseApi {
@@ -24,12 +25,7 @@ export default abstract class BaseApi {
return false
}
checkToken(token: Token, deviceId: string) {
if (token.expired_time < Date.now()) return false
if (!token.author || !User.findById(token.author)) return false
if (deviceId != null)
if (token.device_id != deviceId)
return false
return true
return TokenManager.checkToken(token, deviceId)
}
registerEvent(name: CallMethod, func: EventCallbackFunction) {
if (!name.startsWith(this.getName() + ".")) throw Error("注冊的事件應該與接口集合命名空間相匹配: " + name)