mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
Merge branch 'rc/v2.0' into feature/user-profile
# Conflicts: # src/main/services/hydra-api.ts # src/renderer/src/app.tsx
This commit is contained in:
commit
4f32043966
19 changed files with 278 additions and 17 deletions
|
@ -2,6 +2,9 @@ import { userAuthRepository } from "@main/repository";
|
|||
import axios, { AxiosError, AxiosInstance } from "axios";
|
||||
import { WindowManager } from "./window-manager";
|
||||
import url from "url";
|
||||
import { uploadGamesBatch } from "./library-sync";
|
||||
import { clearGamesRemoteIds } from "./library-sync/clear-games-remote-id";
|
||||
import { logger } from "./logger";
|
||||
|
||||
export class HydraApi {
|
||||
private static instance: AxiosInstance;
|
||||
|
@ -53,6 +56,8 @@ export class HydraApi {
|
|||
|
||||
if (WindowManager.mainWindow) {
|
||||
WindowManager.mainWindow.webContents.send("on-signin");
|
||||
await clearGamesRemoteIds();
|
||||
uploadGamesBatch();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,20 +68,20 @@ export class HydraApi {
|
|||
|
||||
this.instance.interceptors.request.use(
|
||||
(request) => {
|
||||
console.log(" ---- REQUEST -----");
|
||||
console.log(request.method, request.url, request.data);
|
||||
logger.log(" ---- REQUEST -----");
|
||||
logger.log(request.method, request.url, request.data);
|
||||
return request;
|
||||
},
|
||||
(error) => {
|
||||
console.log("request error", error);
|
||||
logger.log("request error", error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
this.instance.interceptors.response.use(
|
||||
(response) => {
|
||||
console.log(" ---- RESPONSE -----");
|
||||
console.log(
|
||||
logger.log(" ---- RESPONSE -----");
|
||||
logger.log(
|
||||
response.status,
|
||||
response.config.method,
|
||||
response.config.url,
|
||||
|
@ -85,7 +90,7 @@ export class HydraApi {
|
|||
return response;
|
||||
},
|
||||
(error) => {
|
||||
console.log("response error", error);
|
||||
logger.error("response error", error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
@ -102,7 +107,11 @@ export class HydraApi {
|
|||
}
|
||||
|
||||
private static async revalidateAccessTokenIfExpired() {
|
||||
if (!this.userAuth.authToken) throw new Error("user is not logged in");
|
||||
if (!this.userAuth.authToken) {
|
||||
userAuthRepository.delete({ id: 1 });
|
||||
logger.error("user is not logged in");
|
||||
throw new Error("user is not logged in");
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
if (this.userAuth.expirationTimestamp < now.getTime()) {
|
||||
|
@ -145,6 +154,8 @@ export class HydraApi {
|
|||
if (WindowManager.mainWindow) {
|
||||
WindowManager.mainWindow.webContents.send("on-signout");
|
||||
}
|
||||
|
||||
logger.log("user refresh token expired");
|
||||
}
|
||||
|
||||
throw err;
|
||||
|
@ -179,4 +190,9 @@ export class HydraApi {
|
|||
await this.revalidateAccessTokenIfExpired();
|
||||
return this.instance.patch(url, data, this.getAxiosConfig());
|
||||
}
|
||||
|
||||
static async delete(url: string) {
|
||||
await this.revalidateAccessTokenIfExpired();
|
||||
return this.instance.delete(url, this.getAxiosConfig());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue