mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-31 06:41:03 +00:00
feat: adding hltb key extraction
This commit is contained in:
@@ -1,45 +1,23 @@
|
||||
import type { GameShop, HowLongToBeatCategory } from "@types";
|
||||
import type { HowLongToBeatCategory } from "@types";
|
||||
import { getHowLongToBeatGame, searchHowLongToBeat } from "@main/services";
|
||||
|
||||
import { registerEvent } from "../register-event";
|
||||
import { gameShopCacheRepository } from "@main/repository";
|
||||
import { formatName } from "@shared";
|
||||
|
||||
const getHowLongToBeat = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
objectId: string,
|
||||
shop: GameShop,
|
||||
title: string
|
||||
): Promise<HowLongToBeatCategory[] | null> => {
|
||||
const searchHowLongToBeatPromise = searchHowLongToBeat(title);
|
||||
const response = await searchHowLongToBeat(title);
|
||||
|
||||
const gameShopCache = await gameShopCacheRepository.findOne({
|
||||
where: { objectID: objectId, shop },
|
||||
const game = response.data.find((game) => {
|
||||
return formatName(game.game_name) === formatName(title);
|
||||
});
|
||||
|
||||
const howLongToBeatCachedData = gameShopCache?.howLongToBeatSerializedData
|
||||
? JSON.parse(gameShopCache?.howLongToBeatSerializedData)
|
||||
: null;
|
||||
if (howLongToBeatCachedData) return howLongToBeatCachedData;
|
||||
if (!game) return null;
|
||||
const howLongToBeat = await getHowLongToBeatGame(String(game.game_id));
|
||||
|
||||
return searchHowLongToBeatPromise.then(async (response) => {
|
||||
const game = response.data.find(
|
||||
(game) => game.profile_steam === Number(objectId)
|
||||
);
|
||||
|
||||
if (!game) return null;
|
||||
const howLongToBeat = await getHowLongToBeatGame(String(game.game_id));
|
||||
|
||||
gameShopCacheRepository.upsert(
|
||||
{
|
||||
objectID: objectId,
|
||||
shop,
|
||||
howLongToBeatSerializedData: JSON.stringify(howLongToBeat),
|
||||
},
|
||||
["objectID"]
|
||||
);
|
||||
|
||||
return howLongToBeat;
|
||||
});
|
||||
return howLongToBeat;
|
||||
};
|
||||
|
||||
registerEvent("getHowLongToBeat", getHowLongToBeat);
|
||||
|
||||
@@ -48,7 +48,9 @@ const updateProfile = async (
|
||||
|
||||
const profileImageUrl = await getNewProfileImageUrl(
|
||||
updateProfile.profileImageUrl
|
||||
).catch(() => undefined);
|
||||
).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
return patchUserProfile({ ...updateProfile, profileImageUrl });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user