mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-19 09:13:57 +00:00
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
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,
|
|
userId: string
|
|
): Promise<UserProfile | null> => {
|
|
try {
|
|
const response = await HydraApi.get(`/user/${userId}`);
|
|
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);
|