diff --git a/client/Data.ts b/client/Data.ts index 3fa9985..0d87a6d 100644 --- a/client/Data.ts +++ b/client/Data.ts @@ -21,6 +21,7 @@ const _data_cached = JSON.parse(_dec) declare global { interface Window { data: { + refresh_token?: string split_sizes: number[] apply(): void access_token?: string @@ -29,6 +30,7 @@ declare global { } } +// @ts-ignore: 忽略... // deno-lint-ignore no-window (window.data == null) && (window.data = new Proxy({ apply() {} diff --git a/client/api/ApiDeclare.ts b/client/api/ApiDeclare.ts index e8593fd..50e123b 100644 --- a/client/api/ApiDeclare.ts +++ b/client/api/ApiDeclare.ts @@ -2,6 +2,7 @@ export type CallMethod = "User.auth" | "User.register" | "User.login" | + "User.refreshAccessToken" | "User.setAvatar" | "User.updateProfile" | @@ -17,6 +18,8 @@ export type CallMethod = "Chat.getInfo" | + "Chat.createGroup" | + "Chat.getIdForPrivate" | "Chat.getAnotherUserIdFromPrivate" | diff --git a/client/api/Client.ts b/client/api/Client.ts index fb7c71b..d58db60 100644 --- a/client/api/Client.ts +++ b/client/api/Client.ts @@ -26,7 +26,7 @@ class Client { }) this.socket!.on("connect", async () => { this.connected = true - const re = await this.auth(data.access_token) + const re = await this.auth(data.access_token as string) if (re.code != 200) checkApiSuccessOrSncakbar(re, "重连失败") }) @@ -42,7 +42,7 @@ class Client { } }) } - static invoke(method: CallMethod, args: unknown = {}, timeout: number = 5000, refreshAndRetryLimit: number = 3, forceRefreshAndRetry: boolean = false): Promise { + static invoke(method: CallMethod, args: object = {}, timeout: number = 5000, refreshAndRetryLimit: number = 3, forceRefreshAndRetry: boolean = false): Promise { // 在 未初始化 / 未建立连接且调用非可调用接口 的时候进行延迟 if (this.socket == null || (!this.connected && !CallableMethodBeforeAuth.includes(method))) { return new Promise((reslove) => { @@ -87,7 +87,7 @@ class Client { const re = await this.invoke("User.refreshAccessToken", { refresh_token: data.refresh_token }) - return re.data?.access_token + return re.data?.access_token as string } static async auth(token: string, timeout: number = 5000) { const re = await this.invoke("User.auth", { diff --git a/server/api/ApiDeclare.ts b/server/api/ApiDeclare.ts index a9aba2c..3ea4484 100644 --- a/server/api/ApiDeclare.ts +++ b/server/api/ApiDeclare.ts @@ -2,6 +2,7 @@ export type CallMethod = "User.auth" | "User.register" | "User.login" | + "User.refreshAccessToken" | "User.setAvatar" | "User.updateProfile" | @@ -17,6 +18,8 @@ export type CallMethod = "Chat.getInfo" | + "Chat.createGroup" | + "Chat.getIdForPrivate" | "Chat.getAnotherUserIdFromPrivate" | diff --git a/server/api/TokenManager.ts b/server/api/TokenManager.ts index 4ea089d..1565165 100644 --- a/server/api/TokenManager.ts +++ b/server/api/TokenManager.ts @@ -32,15 +32,15 @@ export default class TokenManager { } } - static make(user: User, time_: number | null | undefined, device_id: string, type: TokenType = "access_token") { + static make(user: User, time_: number | null | undefined, device_id: string, tokenType: TokenType = "access_token") { const time = (time_ || Date.now()) return this.encode({ author: user.bean.id, auth: this.makeAuth(user), made_time: time, - expired_time: time + (type == 'access_token' ? (1000 * 60 * 60 * 2) : (40 * 1000 * 60 * 60 * 24)), + expired_time: time + (tokenType == 'access_token' ? (1000 * 60 * 60 * 2) : (40 * 1000 * 60 * 60 * 24)), device_id: device_id, - type + type: tokenType }) } /** diff --git a/server/api/UserApi.ts b/server/api/UserApi.ts index 42da2c7..8c2d446 100644 --- a/server/api/UserApi.ts +++ b/server/api/UserApi.ts @@ -295,7 +295,7 @@ export default class UserApi extends BaseApi { const chat = Chat.findById(id) return { id, - type: chat.bean.type, + type: chat?.bean.type, title: chat?.getTitle(user) || "未知", avatar: chat?.getAvatarFileHash(user) ? "uploaded_files/" + chat?.getAvatarFileHash(user) : undefined }