feat: migrating repacks to a worker

This commit is contained in:
Chubby Granny Chaser 2024-06-03 14:34:02 +01:00
parent eb3eb88f23
commit 5a85033486
No known key found for this signature in database
19 changed files with 204 additions and 147 deletions

View file

@ -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"]
);