mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
clean up remnants from details fetch
This commit is contained in:
parent
436fb2707b
commit
09f6a3125b
2 changed files with 23 additions and 26 deletions
|
@ -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;
|
||||||
|
|
|
@ -186,23 +186,28 @@ export async function getExternalIds(
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function formatTMDBSearchResult(
|
export function formatTMDBSearchResult(
|
||||||
result: TMDBShowResult | TMDBMovieResult,
|
result: TMDBShowResult | TMDBMovieResult,
|
||||||
mediatype: TMDBContentTypes
|
mediatype: TMDBContentTypes
|
||||||
): Promise<TMDBMediaResult> {
|
): TMDBMediaResult {
|
||||||
const type = TMDBMediaToMediaType(mediatype);
|
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 {
|
return {
|
||||||
title:
|
title: movie.title,
|
||||||
type === MWMediaType.SERIES
|
poster: getMediaPoster(movie.poster_path),
|
||||||
? (result as TMDBShowResult).name
|
id: movie.id,
|
||||||
: (result as TMDBMovieResult).title,
|
original_release_year: new Date(movie.release_date).getFullYear(),
|
||||||
poster: getMediaPoster(result.poster_path),
|
object_type: mediatype,
|
||||||
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),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue