From e139423b525865036dfd1973627556f0bb12f458 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 17 Sep 2024 21:49:59 -0300 Subject: [PATCH] feat: add axios user agent header with Hydra version --- src/main/constants.ts | 2 ++ src/main/events/index.ts | 6 +++--- src/main/services/hydra-api.ts | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/constants.ts b/src/main/constants.ts index c8cf182f..92973118 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -11,3 +11,5 @@ export const logsPath = path.join(app.getPath("appData"), "hydra", "logs"); export const seedsPath = app.isPackaged ? path.join(process.resourcesPath, "seeds") : path.join(__dirname, "..", "..", "seeds"); + +export const appVersion = app.getVersion(); diff --git a/src/main/events/index.ts b/src/main/events/index.ts index 54e63a3b..0337c9d8 100644 --- a/src/main/events/index.ts +++ b/src/main/events/index.ts @@ -1,5 +1,5 @@ -import { defaultDownloadsPath } from "@main/constants"; -import { app, ipcMain } from "electron"; +import { appVersion, defaultDownloadsPath } from "@main/constants"; +import { ipcMain } from "electron"; import "./catalogue/get-catalogue"; import "./catalogue/get-game-shop-details"; @@ -63,6 +63,6 @@ import "./profile/sync-friend-requests"; import { isPortableVersion } from "@main/helpers"; ipcMain.handle("ping", () => "pong"); -ipcMain.handle("getVersion", () => app.getVersion()); +ipcMain.handle("getVersion", () => appVersion); ipcMain.handle("isPortableVersion", () => isPortableVersion()); ipcMain.handle("getDefaultDownloadsPath", () => defaultDownloadsPath); diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index 90149038..769447a6 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -7,6 +7,7 @@ import { clearGamesRemoteIds } from "./library-sync/clear-games-remote-id"; import { logger } from "./logger"; import { UserNotLoggedInError } from "@shared"; import { omit } from "lodash-es"; +import { appVersion } from "@main/constants"; interface HydraApiOptions { needsAuth: boolean; @@ -80,12 +81,16 @@ export class HydraApi { static async setupApi() { this.instance = axios.create({ baseURL: import.meta.env.MAIN_VITE_API_URL, + headers: { "User-Agent": `Hydra Launcher v${appVersion}` }, }); this.instance.interceptors.request.use( (request) => { logger.log(" ---- REQUEST -----"); - logger.log(request.method, request.url, request.params, request.data); + const data = Array.isArray(request.data) + ? request.data + : omit(request.data, ["refreshToken"]); + logger.log(request.method, request.url, request.params, data); return request; }, (error) => {