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
31
src/main/workers/repacks.worker.ts
Normal file
31
src/main/workers/repacks.worker.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { formatName } from "@shared";
|
||||
import { CatalogueEntry, GameRepack } from "@types";
|
||||
import flexSearch from "flexsearch";
|
||||
|
||||
const repacksIndex = new flexSearch.Index();
|
||||
|
||||
const state: { repacks: GameRepack[] } = { repacks: [] };
|
||||
|
||||
export const setRepacks = (repacks: GameRepack[]) => {
|
||||
state.repacks = repacks;
|
||||
|
||||
for (let i = 0; i < repacks.length; i++) {
|
||||
const repack = repacks[i];
|
||||
|
||||
const formattedTitle = formatName(repack.title);
|
||||
|
||||
repacksIndex.add(i, formattedTitle);
|
||||
}
|
||||
};
|
||||
|
||||
export const search = (options: flexSearch.SearchOptions) =>
|
||||
repacksIndex.search(options).map((index) => state.repacks[index]);
|
||||
|
||||
export const list = () => state.repacks;
|
||||
|
||||
export const findRepacksForCatalogueEntries = (entries: CatalogueEntry[]) => {
|
||||
return entries.map((entry) => {
|
||||
const repacks = search({ query: formatName(entry.title) });
|
||||
return { ...entry, repacks };
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue