mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-24 11:21:02 +00:00
feat: dispatching event when remote games are fetched
This commit is contained in:
@@ -2,7 +2,7 @@ import { userAuthRepository } from "@main/repository";
|
||||
import axios, { AxiosError, AxiosInstance } from "axios";
|
||||
import { WindowManager } from "./window-manager";
|
||||
import url from "url";
|
||||
import { getRemoteGames, uploadBatchGames } from "./library-sync";
|
||||
import { uploadGamesBatch } from "./library-sync";
|
||||
|
||||
export class HydraApi {
|
||||
private static instance: AxiosInstance;
|
||||
@@ -50,9 +50,7 @@ export class HydraApi {
|
||||
|
||||
if (WindowManager.mainWindow) {
|
||||
WindowManager.mainWindow.webContents.send("on-signin");
|
||||
|
||||
await uploadBatchGames();
|
||||
await getRemoteGames();
|
||||
uploadGamesBatch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./get-remote-games";
|
||||
export * from "./upload-batch-games";
|
||||
export * from "./merge-with-remote-games";
|
||||
export * from "./upload-games-batch";
|
||||
export * from "./update-game-playtime";
|
||||
export * from "./create-game";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getSteamAppAsset } from "@main/helpers";
|
||||
import { logger } from "../logger";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
export const getRemoteGames = async () => {
|
||||
export const mergeWithRemoteGames = async () => {
|
||||
try {
|
||||
const games = await HydraApi.get("/games");
|
||||
|
||||
@@ -5,13 +5,17 @@ import { HydraApi } from "../hydra-api";
|
||||
import { logger } from "../logger";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
export const uploadBatchGames = async () => {
|
||||
import { mergeWithRemoteGames } from "./merge-with-remote-games";
|
||||
import { WindowManager } from "../window-manager";
|
||||
|
||||
export const uploadGamesBatch = async () => {
|
||||
try {
|
||||
const games = await gameRepository.find({
|
||||
where: { remoteId: IsNull(), isDeleted: false },
|
||||
});
|
||||
|
||||
const gamesChunks = chunk(games, 200);
|
||||
|
||||
for (const chunk of gamesChunks) {
|
||||
await HydraApi.post(
|
||||
"/games/batch",
|
||||
@@ -25,11 +29,16 @@ export const uploadBatchGames = async () => {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
await mergeWithRemoteGames();
|
||||
|
||||
if (WindowManager.mainWindow)
|
||||
WindowManager.mainWindow.webContents.send("on-library-batch-complete");
|
||||
} catch (err) {
|
||||
if (err instanceof AxiosError) {
|
||||
logger.error("uploadBatchGames", err.response, err.message);
|
||||
logger.error("uploadGamesBatch", err.response, err.message);
|
||||
} else {
|
||||
logger.error("uploadBatchGames", err);
|
||||
logger.error("uploadGamesBatch", err);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user