mirror of
				https://github.com/hydralauncher/hydra.git
				synced 2025-03-09 15:40:26 +00:00 
			
		
		
		
	feat: adding import download source
This commit is contained in:
		
							parent
							
								
									ddd9ea69df
								
							
						
					
					
						commit
						48e07370e4
					
				
					 70 changed files with 925 additions and 1261 deletions
				
			
		|  | @ -1,40 +1,11 @@ | |||
| import flexSearch from "flexsearch"; | ||||
| import { orderBy } from "lodash-es"; | ||||
| import flexSearch from "flexsearch"; | ||||
| 
 | ||||
| import type { GameRepack, GameShop, CatalogueEntry } from "@types"; | ||||
| import type { GameShop, CatalogueEntry, SteamGame } from "@types"; | ||||
| 
 | ||||
| import { formatName, getSteamAppAsset, repackerFormatter } from "@main/helpers"; | ||||
| import { stateManager } from "@main/state-manager"; | ||||
| 
 | ||||
| const { Index } = flexSearch; | ||||
| const repacksIndex = new Index(); | ||||
| const steamGamesIndex = new Index({ tokenize: "forward" }); | ||||
| 
 | ||||
| const repacks = stateManager.getValue("repacks"); | ||||
| const steamGames = stateManager.getValue("steamGames"); | ||||
| 
 | ||||
| for (let i = 0; i < repacks.length; i++) { | ||||
|   const repack = repacks[i]; | ||||
|   const formatter = | ||||
|     repackerFormatter[repack.repacker as keyof typeof repackerFormatter]; | ||||
| 
 | ||||
|   repacksIndex.add(i, formatName(formatter(repack.title))); | ||||
| } | ||||
| 
 | ||||
| for (let i = 0; i < steamGames.length; i++) { | ||||
|   const steamGame = steamGames[i]; | ||||
|   steamGamesIndex.add(i, formatName(steamGame.name)); | ||||
| } | ||||
| 
 | ||||
| export const searchRepacks = (title: string): GameRepack[] => { | ||||
|   return orderBy( | ||||
|     repacksIndex | ||||
|       .search(formatName(title)) | ||||
|       .map((index) => repacks.at(index as number)!), | ||||
|     ["uploadDate"], | ||||
|     "desc" | ||||
|   ); | ||||
| }; | ||||
| import { getSteamAppAsset } from "@main/helpers"; | ||||
| import { SearchEngine } from "@main/services"; | ||||
| import { steamGamesWorker } from "@main/workers"; | ||||
| 
 | ||||
| export interface SearchGamesArgs { | ||||
|   query?: string; | ||||
|  | @ -42,27 +13,25 @@ export interface SearchGamesArgs { | |||
|   skip?: number; | ||||
| } | ||||
| 
 | ||||
| export const searchGames = ({ | ||||
|   query, | ||||
|   take, | ||||
|   skip, | ||||
| }: SearchGamesArgs): CatalogueEntry[] => { | ||||
|   const results = steamGamesIndex | ||||
|     .search(formatName(query || ""), { limit: take, offset: skip }) | ||||
|     .map((index) => { | ||||
|       const result = steamGames.at(index as number)!; | ||||
| 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), | ||||
|   }; | ||||
| }; | ||||
| 
 | ||||
|       return { | ||||
|         objectID: String(result.id), | ||||
|         title: result.name, | ||||
|         shop: "steam" as GameShop, | ||||
|         cover: getSteamAppAsset("library", String(result.id)), | ||||
|         repacks: searchRepacks(result.name), | ||||
|       }; | ||||
|     }); | ||||
| export const searchSteamGames = async ( | ||||
|   options: flexSearch.SearchOptions | ||||
| ): Promise<CatalogueEntry[]> => { | ||||
|   const steamGames = await steamGamesWorker.run(options, { name: "search" }); | ||||
| 
 | ||||
|   return orderBy( | ||||
|     results, | ||||
|     steamGames.map((result) => convertSteamGameToCatalogueEntry(result)), | ||||
|     [({ repacks }) => repacks.length, "repacks"], | ||||
|     ["desc"] | ||||
|   ); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue