mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-22 18:33:56 +00:00
feat: showing first content on profile page
This commit is contained in:
@@ -2,20 +2,41 @@ import { registerEvent } from "../register-event";
|
||||
import { userProfileSchema } from "../helpers/validators";
|
||||
import { logger } from "@main/services";
|
||||
import { HydraApi } from "@main/services/hydra-api";
|
||||
import { steamGamesWorker } from "@main/workers";
|
||||
import { LibraryGame, SteamGame, UserProfile } from "@types";
|
||||
|
||||
const getUserProfile = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
username: string
|
||||
) => {
|
||||
return HydraApi.get(`/profile/${username}`)
|
||||
.then((response) => {
|
||||
const profile = userProfileSchema.parse(response.data);
|
||||
return profile;
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(`getUserProfile: ${username}`, err);
|
||||
return null;
|
||||
});
|
||||
): Promise<UserProfile | null> => {
|
||||
try {
|
||||
const response = await HydraApi.get(`/profile/${username}`);
|
||||
const profile = userProfileSchema.parse(response.data);
|
||||
|
||||
const recentGames = await Promise.all(
|
||||
profile.recentGames.map(async (game) => {
|
||||
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
|
||||
name: "getById",
|
||||
});
|
||||
|
||||
return { ...game, title: steamGame.name, objectId: game.objectId };
|
||||
})
|
||||
);
|
||||
|
||||
const libraryGames = await Promise.all(
|
||||
profile.game.map(async (game) => {
|
||||
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
|
||||
name: "getById",
|
||||
});
|
||||
return { ...game, title: steamGame.name, objectID: game.objectId };
|
||||
})
|
||||
);
|
||||
|
||||
return { ...profile, game: libraryGames, recentGames };
|
||||
} catch (err) {
|
||||
logger.error(`getUserProfile: ${username}`, err);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
registerEvent("getUserProfile", getUserProfile);
|
||||
|
||||
Reference in New Issue
Block a user