feat: user profile

This commit is contained in:
Zamitto
2024-06-11 22:09:24 -03:00
parent 8fad9b05e6
commit a974141360
8 changed files with 77 additions and 0 deletions

View File

@@ -12,3 +12,19 @@ export const downloadSourceSchema = z.object({
})
),
});
const gamesArray = z.array(
z.object({
id: z.number(),
objectId: z.string().max(255),
playTimeInMilliseconds: z.number().int(),
shop: z.enum(["steam", "epic"]),
lastTimePlayed: z.coerce.date().nullable(),
})
);
export const userProfileSchema = z.object({
username: z.string(),
game: gamesArray,
recentGames: gamesArray,
});

View File

@@ -39,6 +39,7 @@ import "./download-sources/validate-download-source";
import "./download-sources/add-download-source";
import "./download-sources/remove-download-source";
import "./download-sources/sync-download-sources";
import "./profile/get-user-profile";
ipcMain.handle("ping", () => "pong");
ipcMain.handle("getVersion", () => app.getVersion());

View File

@@ -0,0 +1,23 @@
import axios from "axios";
import { registerEvent } from "../register-event";
import { userProfileSchema } from "../helpers/validators";
import { logger } from "@main/services";
const getUserProfile = async (
_event: Electron.IpcMainInvokeEvent,
username: string
) => {
return axios
.get(`${process.env.API_URL}/profile/${username}`)
.then((response) => {
const profile = userProfileSchema.parse(response.data);
console.log(profile);
return profile;
})
.catch((err) => {
logger.error(`getUserProfile: ${username}`, err);
return null;
});
};
registerEvent("getUserProfiel", getUserProfile);