|
|
@ -7,7 +7,6 @@ import { |
|
|
|
searchMedia, |
|
|
|
searchMedia, |
|
|
|
} from "./tmdb"; |
|
|
|
} from "./tmdb"; |
|
|
|
import { MWMediaMeta, MWQuery } from "./types/mw"; |
|
|
|
import { MWMediaMeta, MWQuery } from "./types/mw"; |
|
|
|
import { TMDBMovieResponse, TMDBShowResponse } from "./types/tmdb"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cache = new SimpleCache<MWQuery, MWMediaMeta[]>(); |
|
|
|
const cache = new SimpleCache<MWQuery, MWMediaMeta[]>(); |
|
|
|
cache.setCompare((a, b) => { |
|
|
|
cache.setCompare((a, b) => { |
|
|
@ -19,18 +18,11 @@ export async function searchForMedia(query: MWQuery): Promise<MWMediaMeta[]> { |
|
|
|
if (cache.has(query)) return cache.get(query) as MWMediaMeta[]; |
|
|
|
if (cache.has(query)) return cache.get(query) as MWMediaMeta[]; |
|
|
|
const { searchQuery, type } = query; |
|
|
|
const { searchQuery, type } = query; |
|
|
|
|
|
|
|
|
|
|
|
const data = (await searchMedia(searchQuery, mediaTypeToTMDB(type))) as |
|
|
|
const data = await searchMedia(searchQuery, mediaTypeToTMDB(type)); |
|
|
|
| TMDBMovieResponse |
|
|
|
const results = data.results.map((v) => { |
|
|
|
| TMDBShowResponse; |
|
|
|
const formattedResult = formatTMDBSearchResult(v, mediaTypeToTMDB(type)); |
|
|
|
const results = await Promise.all( |
|
|
|
return formatTMDBMeta(formattedResult); |
|
|
|
data.results.map(async (v) => { |
|
|
|
}); |
|
|
|
const formattedResult = await formatTMDBSearchResult( |
|
|
|
|
|
|
|
v, |
|
|
|
|
|
|
|
mediaTypeToTMDB(type) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return formatTMDBMeta(formattedResult); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache.set(query, results, 3600); // cache results for 1 hour
|
|
|
|
cache.set(query, results, 3600); // cache results for 1 hour
|
|
|
|
return results; |
|
|
|
return results; |
|
|
|