feat: 緩存資料, 獲取任意用戶的資料

This commit is contained in:
CrescentLeaf
2025-09-21 16:13:01 +08:00
parent f118c6b6f5
commit e4c26a07cf
4 changed files with 53 additions and 1 deletions

19
client/api/DataCaches.ts Normal file
View File

@@ -0,0 +1,19 @@
import data from "../Data.ts"
import Client from "./Client.ts"
import User from "./client_data/User.ts"
export default class DataCaches {
static userProfiles: { [key: string]: User} = {}
static async getUserProfile(userId: string): Promise<User> {
if (this.userProfiles[userId]) return this.userProfiles[userId]
const re = await Client.invoke("User.getInfo", {
token: data.access_token,
target: userId
})
if (re.code != 200) return {
id: '',
nickname: "",
}
return this.userProfiles[userId] = (re.data as unknown as User)
}
}