mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-20 09:43:57 +00:00
Merge branch 'main' into feature/better-repack-modal
This commit is contained in:
@@ -1,10 +1,32 @@
|
||||
import { gameShopCacheRepository } from "@main/repository";
|
||||
import { gameShopCacheRepository, steamGameRepository } from "@main/repository";
|
||||
import { getSteamAppDetails } from "@main/services";
|
||||
|
||||
import type { ShopDetails, GameShop, SteamAppDetails } from "@types";
|
||||
|
||||
import { registerEvent } from "../register-event";
|
||||
import { searchRepacks } from "../helpers/search-games";
|
||||
|
||||
const getLocalizedSteamAppDetails = (
|
||||
objectID: string,
|
||||
language: string
|
||||
): Promise<ShopDetails | null> => {
|
||||
if (language === "english") {
|
||||
return getSteamAppDetails(objectID, language);
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
steamGameRepository.findOne({ where: { id: Number(objectID) } }),
|
||||
getSteamAppDetails(objectID, language),
|
||||
]).then(([steamGame, localizedAppDetails]) => {
|
||||
if (steamGame && localizedAppDetails) {
|
||||
return {
|
||||
...localizedAppDetails,
|
||||
name: steamGame.name,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
const getGameShopDetails = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
@@ -17,27 +39,21 @@ const getGameShopDetails = async (
|
||||
where: { objectID, language },
|
||||
});
|
||||
|
||||
const result = Promise.all([
|
||||
getSteamAppDetails(objectID, "english"),
|
||||
getSteamAppDetails(objectID, language),
|
||||
]).then(([appDetails, localizedAppDetails]) => {
|
||||
if (appDetails && localizedAppDetails) {
|
||||
const appDetails = getLocalizedSteamAppDetails(objectID, language).then(
|
||||
(result) => {
|
||||
gameShopCacheRepository.upsert(
|
||||
{
|
||||
objectID,
|
||||
shop: "steam",
|
||||
language,
|
||||
serializedData: JSON.stringify({
|
||||
...localizedAppDetails,
|
||||
name: appDetails.name,
|
||||
}),
|
||||
serializedData: JSON.stringify(result),
|
||||
},
|
||||
["objectID"]
|
||||
);
|
||||
}
|
||||
|
||||
return [appDetails, localizedAppDetails];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
);
|
||||
|
||||
const cachedGame = cachedData?.serializedData
|
||||
? (JSON.parse(cachedData?.serializedData) as SteamAppDetails)
|
||||
@@ -46,21 +62,11 @@ const getGameShopDetails = async (
|
||||
if (cachedGame) {
|
||||
return {
|
||||
...cachedGame,
|
||||
repacks: searchRepacks(cachedGame.name),
|
||||
objectID,
|
||||
} as ShopDetails;
|
||||
}
|
||||
|
||||
return result.then(([appDetails, localizedAppDetails]) => {
|
||||
if (!appDetails || !localizedAppDetails) return null;
|
||||
|
||||
return {
|
||||
...localizedAppDetails,
|
||||
name: appDetails.name,
|
||||
repacks: searchRepacks(appDetails.name),
|
||||
objectID,
|
||||
} as ShopDetails;
|
||||
});
|
||||
return Promise.resolve(appDetails);
|
||||
}
|
||||
|
||||
throw new Error("Not implemented");
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { shuffle } from "lodash-es";
|
||||
|
||||
import { Steam250Game, getSteam250List } from "@main/services";
|
||||
import { getSteam250List } from "@main/services";
|
||||
|
||||
import { registerEvent } from "../register-event";
|
||||
import { searchGames, searchRepacks } from "../helpers/search-games";
|
||||
import type { Steam250Game } from "@types";
|
||||
|
||||
const state = { games: Array<Steam250Game>(), index: 0 };
|
||||
|
||||
@@ -25,8 +26,6 @@ const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
return "";
|
||||
}
|
||||
|
||||
const resultObjectId = state.games[state.index].objectID;
|
||||
|
||||
state.index += 1;
|
||||
|
||||
if (state.index == state.games.length) {
|
||||
@@ -34,7 +33,7 @@ const getRandomGame = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
state.games = shuffle(state.games);
|
||||
}
|
||||
|
||||
return resultObjectId;
|
||||
return state.games[state.index];
|
||||
};
|
||||
|
||||
registerEvent(getRandomGame, {
|
||||
|
||||
14
src/main/events/catalogue/search-game-repacks.ts
Normal file
14
src/main/events/catalogue/search-game-repacks.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { searchRepacks } from "../helpers/search-games";
|
||||
import { registerEvent } from "../register-event";
|
||||
|
||||
const searchGameRepacks = (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
query: string
|
||||
) => {
|
||||
return searchRepacks(query);
|
||||
};
|
||||
|
||||
registerEvent(searchGameRepacks, {
|
||||
name: "searchGameRepacks",
|
||||
memoize: true,
|
||||
});
|
||||
@@ -8,6 +8,7 @@ import "./catalogue/get-how-long-to-beat";
|
||||
import "./catalogue/get-random-game";
|
||||
import "./catalogue/search-games";
|
||||
import "./catalogue/repacks/get-magnet-health";
|
||||
import "./catalogue/search-game-repacks";
|
||||
import "./hardware/get-disk-free-space";
|
||||
import "./library/add-game-to-library";
|
||||
import "./library/close-game";
|
||||
|
||||
@@ -12,8 +12,7 @@ export class RealDebridClient {
|
||||
private static instance: AxiosInstance;
|
||||
|
||||
static async addMagnet(magnet: string) {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.append("magnet", magnet);
|
||||
const searchParams = new URLSearchParams({ magnet });
|
||||
|
||||
const response = await this.instance.post<RealDebridAddMagnet>(
|
||||
"/torrents/addMagnet",
|
||||
@@ -31,8 +30,7 @@ export class RealDebridClient {
|
||||
}
|
||||
|
||||
static async selectAllFiles(id: string) {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.append("files", "all");
|
||||
const searchParams = new URLSearchParams({ files: "all" });
|
||||
|
||||
await this.instance.post(
|
||||
`/torrents/selectFiles/${id}`,
|
||||
@@ -41,8 +39,7 @@ export class RealDebridClient {
|
||||
}
|
||||
|
||||
static async unrestrictLink(link: string) {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.append("link", link);
|
||||
const searchParams = new URLSearchParams({ link });
|
||||
|
||||
const response = await this.instance.post<RealDebridUnrestrictLink>(
|
||||
"/unrestrict/link",
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import axios from "axios";
|
||||
import { JSDOM } from "jsdom";
|
||||
|
||||
export interface Steam250Game {
|
||||
title: string;
|
||||
objectID: string;
|
||||
}
|
||||
import type { Steam250Game } from "@types";
|
||||
|
||||
export const requestSteam250 = async (path: string) => {
|
||||
return axios
|
||||
|
||||
Reference in New Issue
Block a user