mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-26 19:51:49 +01:00
Merge pull request #1108 from meghrathod/dev
Added alternate tmdb endpoint to fallback when main url is blocked
This commit is contained in:
commit
44694c6c5a
@ -144,6 +144,8 @@ export function decodeTMDBId(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const baseURL = "https://api.themoviedb.org/3";
|
const baseURL = "https://api.themoviedb.org/3";
|
||||||
|
const otherUrl = "https://api.tmdb.org/3";
|
||||||
|
let useFallback = false;
|
||||||
|
|
||||||
const apiKey = conf().TMDB_READ_API_KEY;
|
const apiKey = conf().TMDB_READ_API_KEY;
|
||||||
|
|
||||||
@ -154,14 +156,26 @@ const headers = {
|
|||||||
|
|
||||||
async function get<T>(url: string, params?: object): Promise<T> {
|
async function get<T>(url: string, params?: object): Promise<T> {
|
||||||
if (!apiKey) throw new Error("TMDB API key not set");
|
if (!apiKey) throw new Error("TMDB API key not set");
|
||||||
|
let res: T;
|
||||||
const res = await mwFetch<any>(encodeURI(url), {
|
try {
|
||||||
|
res = await mwFetch<T>(encodeURI(url), {
|
||||||
headers,
|
headers,
|
||||||
baseURL,
|
baseURL: !useFallback ? baseURL : otherUrl,
|
||||||
|
params: {
|
||||||
|
...params,
|
||||||
|
},
|
||||||
|
signal: AbortSignal.timeout(!useFallback ? 5000 : 30000),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
useFallback = true;
|
||||||
|
res = await mwFetch<T>(encodeURI(url), {
|
||||||
|
headers,
|
||||||
|
baseURL: otherUrl,
|
||||||
params: {
|
params: {
|
||||||
...params,
|
...params,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user