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

@ -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 };
});
};