mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
31 lines
879 B
TypeScript
31 lines
879 B
TypeScript
import { Game } from "@main/entity";
|
|
import { HydraApi } from "../hydra-api";
|
|
import { gameRepository } from "@main/repository";
|
|
import { logger } from "../logger";
|
|
|
|
export const createGame = async (game: Game) => {
|
|
HydraApi.post(
|
|
"/games/download",
|
|
{
|
|
objectId: game.objectID,
|
|
shop: game.shop,
|
|
},
|
|
{ needsAuth: false }
|
|
).catch((err) => {
|
|
logger.error("Failed to create game download", err);
|
|
});
|
|
|
|
return HydraApi.post(`/profile/games`, {
|
|
objectId: game.objectID,
|
|
playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds),
|
|
shop: game.shop,
|
|
lastTimePlayed: game.lastTimePlayed,
|
|
}).then((response) => {
|
|
const { id: remoteId, playTimeInMilliseconds, lastTimePlayed } = response;
|
|
|
|
gameRepository.update(
|
|
{ objectID: game.objectID },
|
|
{ remoteId, playTimeInMilliseconds, lastTimePlayed }
|
|
);
|
|
});
|
|
};
|