feat: refactor

This commit is contained in:
Zamitto 2024-09-25 18:16:32 -03:00
parent f98432f6c6
commit 25cfdb50d8
7 changed files with 28 additions and 12 deletions

View File

@ -67,7 +67,6 @@ const runMigrations = async () => {
);
});
await knexClient.migrate.down(migrationConfig);
await knexClient.migrate.latest(migrationConfig);
await knexClient.destroy();
};

View File

@ -16,7 +16,7 @@ import { publishNewRepacksNotifications } from "./services/notifications";
import { MoreThan } from "typeorm";
import { HydraApi } from "./services/hydra-api";
import { uploadGamesBatch } from "./services/library-sync";
import { saveAllLocalSteamAchivements } from "./services/achievements/services/save-all-local-steam-achivements";
import { saveAllLocalSteamAchivements } from "./services/achievements/save-all-local-steam-achivements";
const loadState = async (userPreferences: UserPreferences | null) => {
RepacksManager.updateRepacks();
@ -59,8 +59,6 @@ const loadState = async (userPreferences: UserPreferences | null) => {
if (newRepacksCount > 0) publishNewRepacksNotifications(newRepacksCount);
});
saveAllLocalSteamAchivements();
};
userPreferencesRepository

View File

@ -1,5 +1,5 @@
import { watch } from "node:fs/promises";
import { getGameAchievementsToWatch } from "./services/get-game-achievements-to-watch";
import { getGameAchievementsToWatch } from "./get-game-achievements-to-watch";
import { checkUnlockedAchievements } from "./util/check-unlocked-achievements";
import { parseAchievementFile } from "./util/parseAchievementFile";
import { gameAchievementRepository } from "@main/repository";

View File

@ -1,9 +1,9 @@
import { gameRepository, gameAchievementRepository } from "@main/repository";
import { steamGetAchivement } from "../steam/steam-get-achivement";
import { steamFindGameAchievementFiles } from "../steam/steam-find-game-achivement-files";
import { AchievementFile, CheckedAchievements } from "../types";
import { parseAchievementFile } from "../util/parseAchievementFile";
import { checkUnlockedAchievements } from "../util/check-unlocked-achievements";
import { steamGetAchivement } from "./steam/steam-get-achivement";
import { steamFindGameAchievementFiles } from "./steam/steam-find-game-achivement-files";
import { AchievementFile, CheckedAchievements } from "./types";
import { parseAchievementFile } from "./util/parseAchievementFile";
import { checkUnlockedAchievements } from "./util/check-unlocked-achievements";
export const getGameAchievementsToWatch = async (
gameId: number

View File

@ -0,0 +1,7 @@
import { HydraApi } from "../hydra-api";
export const mergeWithRemoteAchievements = async () => {
return HydraApi.get("/profile/games/achievements").then(async (response) => {
console.log(response);
});
};

View File

@ -1,6 +1,6 @@
import { gameAchievementRepository, gameRepository } from "@main/repository";
import { steamFindGameAchievementFiles } from "../steam/steam-find-game-achivement-files";
import { parseAchievementFile } from "../util/parseAchievementFile";
import { steamFindGameAchievementFiles } from "./steam/steam-find-game-achivement-files";
import { parseAchievementFile } from "./util/parseAchievementFile";
import { HydraApi } from "@main/services";
export const saveAllLocalSteamAchivements = async () => {
@ -68,5 +68,14 @@ export const saveAllLocalSteamAchivements = async () => {
},
["objectId", "shop"]
);
if (game.remoteId) {
HydraApi.put("/profile/games/achievements", {
id: game.remoteId,
achievements: unlockedAchievements,
}).catch(() => {
console.log("erro");
});
}
}
};

View File

@ -4,6 +4,7 @@ import { IsNull } from "typeorm";
import { HydraApi } from "../hydra-api";
import { mergeWithRemoteGames } from "./merge-with-remote-games";
import { WindowManager } from "../window-manager";
import { saveAllLocalSteamAchivements } from "../achievements/save-all-local-steam-achivements";
export const uploadGamesBatch = async () => {
const games = await gameRepository.find({
@ -28,6 +29,8 @@ export const uploadGamesBatch = async () => {
await mergeWithRemoteGames();
await saveAllLocalSteamAchivements();
if (WindowManager.mainWindow)
WindowManager.mainWindow.webContents.send("on-library-batch-complete");
};