From 926018310e0cb5fad8dc0f61ea7bd23b3adf0dd9 Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sun, 14 Apr 2024 21:29:45 +0100 Subject: [PATCH] Fix TMDB code --- src/backend/metadata/tmdb.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index 67a79490..331f022f 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -143,40 +143,37 @@ export function decodeTMDBId( }; } -const baseURL = "https://api.themoviedb.org/3"; -const otherUrl = "https://api.tmdb.org/3"; -let useFallback = false; +const tmdbBaseUrl1 = "https://api.themoviedb.org/3"; +const tmdbBaseUrl2 = "https://api.tmdb.org/3"; const apiKey = conf().TMDB_READ_API_KEY; -const headers = { +const tmdbHeaders = { accept: "application/json", Authorization: `Bearer ${apiKey}`, }; async function get(url: string, params?: object): Promise { if (!apiKey) throw new Error("TMDB API key not set"); - let res: T; try { - res = await mwFetch(encodeURI(url), { - headers, - baseURL: !useFallback ? baseURL : otherUrl, + return await mwFetch(encodeURI(url), { + headers: tmdbHeaders, + baseURL: tmdbBaseUrl1, params: { ...params, }, - signal: AbortSignal.timeout(!useFallback ? 5000 : 30000), + signal: AbortSignal.timeout(5000), }); } catch (err) { - useFallback = true; - res = await mwFetch(encodeURI(url), { - headers, - baseURL: otherUrl, + return mwFetch(encodeURI(url), { + headers: tmdbHeaders, + baseURL: tmdbBaseUrl2, params: { ...params, }, + signal: AbortSignal.timeout(30000), }); } - return res; } export async function multiSearch(