feat: handle login from deeplink

This commit is contained in:
Zamitto 2024-06-16 13:58:24 -03:00
parent 55c214eae6
commit 32566e5dfc
17 changed files with 243 additions and 62 deletions

View file

@ -0,0 +1,56 @@
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services/hydra-api";
import { steamGamesWorker } from "@main/workers";
import { UserProfile } from "@types";
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
import { getSteamAppAsset } from "@main/helpers";
const getUser = async (
_event: Electron.IpcMainInvokeEvent,
username: string
): Promise<UserProfile | null> => {
try {
const response = await HydraApi.get(`/user/${username}`);
const profile = response.data;
const recentGames = await Promise.all(
profile.recentGames.map(async (game) => {
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
name: "getById",
});
const iconUrl = steamGame?.clientIcon
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
: null;
return {
...game,
...convertSteamGameToCatalogueEntry(steamGame),
iconUrl,
};
})
);
const libraryGames = await Promise.all(
profile.libraryGames.map(async (game) => {
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
name: "getById",
});
const iconUrl = steamGame?.clientIcon
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
: null;
return {
...game,
...convertSteamGameToCatalogueEntry(steamGame),
iconUrl,
};
})
);
return { ...profile, libraryGames, recentGames };
} catch (err) {
return null;
}
};
registerEvent("getUser", getUser);