feat: auto generate api types

This commit is contained in:
naiba
2024-11-09 00:07:21 +08:00
parent 680dc219d3
commit f842d5aeec
13 changed files with 1315 additions and 155 deletions
+9
View File
@@ -22,6 +22,8 @@ export enum FetcherMethod {
DELETE = "DELETE",
}
let lastestRefreshTokenAt = 0;
export async function fetcher<T>(method: FetcherMethod, path: string, data?: any): Promise<T> {
let response;
if (method === FetcherMethod.GET || method === FetcherMethod.DELETE) {
@@ -44,6 +46,13 @@ export async function fetcher<T>(method: FetcherMethod, path: string, data?: any
if (!responseData.success) {
throw new Error(responseData.error);
}
// auto refresh token
if (!lastestRefreshTokenAt || Date.now() - lastestRefreshTokenAt > 1000 * 60 * 60) {
lastestRefreshTokenAt = Date.now();
fetch("/api/v1/refresh-token")
}
return responseData.data;
}