mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: migrating repacks to a worker
This commit is contained in:
parent
eb3eb88f23
commit
5a85033486
19 changed files with 204 additions and 147 deletions
|
@ -4,8 +4,7 @@ import flexSearch from "flexsearch";
|
|||
import type { GameShop, CatalogueEntry, SteamGame } from "@types";
|
||||
|
||||
import { getSteamAppAsset } from "@main/helpers";
|
||||
import { SearchEngine } from "@main/services";
|
||||
import { steamGamesWorker } from "@main/workers";
|
||||
import { repacksWorker, steamGamesWorker } from "@main/workers";
|
||||
|
||||
export interface SearchGamesArgs {
|
||||
query?: string;
|
||||
|
@ -14,24 +13,31 @@ export interface SearchGamesArgs {
|
|||
}
|
||||
|
||||
export const convertSteamGameToCatalogueEntry = (
|
||||
result: SteamGame
|
||||
): CatalogueEntry => {
|
||||
return {
|
||||
objectID: String(result.id),
|
||||
title: result.name,
|
||||
shop: "steam" as GameShop,
|
||||
cover: getSteamAppAsset("library", String(result.id)),
|
||||
repacks: SearchEngine.searchRepacks(result.name),
|
||||
};
|
||||
};
|
||||
game: SteamGame
|
||||
): CatalogueEntry => ({
|
||||
objectID: String(game.id),
|
||||
title: game.name,
|
||||
shop: "steam" as GameShop,
|
||||
cover: getSteamAppAsset("library", String(game.id)),
|
||||
repacks: [],
|
||||
});
|
||||
|
||||
export const searchSteamGames = async (
|
||||
options: flexSearch.SearchOptions
|
||||
): Promise<CatalogueEntry[]> => {
|
||||
const steamGames = await steamGamesWorker.run(options, { name: "search" });
|
||||
const steamGames = (await steamGamesWorker.run(options, {
|
||||
name: "search",
|
||||
})) as SteamGame[];
|
||||
|
||||
const result = await repacksWorker.run(
|
||||
steamGames.map((game) => convertSteamGameToCatalogueEntry(game)),
|
||||
{
|
||||
name: "findRepacksForCatalogueEntries",
|
||||
}
|
||||
);
|
||||
|
||||
return orderBy(
|
||||
steamGames.map((result) => convertSteamGameToCatalogueEntry(result)),
|
||||
result,
|
||||
[({ repacks }) => repacks.length, "repacks"],
|
||||
["desc"]
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue