diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index 67c7d56f..67a79490 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -144,6 +144,8 @@ export function decodeTMDBId( } const baseURL = "https://api.themoviedb.org/3"; +const otherUrl = "https://api.tmdb.org/3"; +let useFallback = false; const apiKey = conf().TMDB_READ_API_KEY; @@ -154,14 +156,26 @@ const headers = { async function get(url: string, params?: object): Promise { if (!apiKey) throw new Error("TMDB API key not set"); - - const res = await mwFetch(encodeURI(url), { - headers, - baseURL, - params: { - ...params, - }, - }); + let res: T; + try { + res = await mwFetch(encodeURI(url), { + headers, + baseURL: !useFallback ? baseURL : otherUrl, + params: { + ...params, + }, + signal: AbortSignal.timeout(!useFallback ? 5000 : 30000), + }); + } catch (err) { + useFallback = true; + res = await mwFetch(encodeURI(url), { + headers, + baseURL: otherUrl, + params: { + ...params, + }, + }); + } return res; }