From 09f6a3125b7b3a6c0841f4c8408a724cfa153e97 Mon Sep 17 00:00:00 2001 From: adrifcastr Date: Wed, 21 Jun 2023 13:54:34 +0200 Subject: [PATCH] clean up remnants from details fetch --- src/backend/metadata/search.ts | 18 +++++------------- src/backend/metadata/tmdb.ts | 31 ++++++++++++++++++------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/backend/metadata/search.ts b/src/backend/metadata/search.ts index 99cb51ba..0d8f561f 100644 --- a/src/backend/metadata/search.ts +++ b/src/backend/metadata/search.ts @@ -7,7 +7,6 @@ import { searchMedia, } from "./tmdb"; import { MWMediaMeta, MWQuery } from "./types/mw"; -import { TMDBMovieResponse, TMDBShowResponse } from "./types/tmdb"; const cache = new SimpleCache(); cache.setCompare((a, b) => { @@ -19,18 +18,11 @@ export async function searchForMedia(query: MWQuery): Promise { if (cache.has(query)) return cache.get(query) as MWMediaMeta[]; const { searchQuery, type } = query; - const data = (await searchMedia(searchQuery, mediaTypeToTMDB(type))) as - | TMDBMovieResponse - | TMDBShowResponse; - const results = await Promise.all( - data.results.map(async (v) => { - const formattedResult = await formatTMDBSearchResult( - v, - mediaTypeToTMDB(type) - ); - return formatTMDBMeta(formattedResult); - }) - ); + const data = await searchMedia(searchQuery, mediaTypeToTMDB(type)); + const results = data.results.map((v) => { + const formattedResult = formatTMDBSearchResult(v, mediaTypeToTMDB(type)); + return formatTMDBMeta(formattedResult); + }); cache.set(query, results, 3600); // cache results for 1 hour return results; diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index 4a9271ba..4c3259a3 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -186,23 +186,28 @@ export async function getExternalIds( return data; } -export async function formatTMDBSearchResult( +export function formatTMDBSearchResult( result: TMDBShowResult | TMDBMovieResult, mediatype: TMDBContentTypes -): Promise { +): TMDBMediaResult { const type = TMDBMediaToMediaType(mediatype); + if (type === MWMediaType.SERIES) { + const show = result as TMDBShowResult; + return { + title: show.name, + poster: getMediaPoster(show.poster_path), + id: show.id, + original_release_year: new Date(show.first_air_date).getFullYear(), + object_type: mediatype, + }; + } + const movie = result as TMDBMovieResult; return { - title: - type === MWMediaType.SERIES - ? (result as TMDBShowResult).name - : (result as TMDBMovieResult).title, - poster: getMediaPoster(result.poster_path), - id: result.id, - original_release_year: - type === MWMediaType.SERIES - ? Number((result as TMDBShowResult).first_air_date?.split("-")[0]) - : Number((result as TMDBMovieResult).release_date?.split("-")[0]), - object_type: mediaTypeToTMDB(type), + title: movie.title, + poster: getMediaPoster(movie.poster_path), + id: movie.id, + original_release_year: new Date(movie.release_date).getFullYear(), + object_type: mediatype, }; }