mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-26 04:11:02 +00:00
feat: user profile
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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());
|
||||
|
||||
23
src/main/events/profile/get-user-profile.ts
Normal file
23
src/main/events/profile/get-user-profile.ts
Normal 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);
|
||||
Reference in New Issue
Block a user