mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
Use vanilla AbortController for compat
This commit is contained in:
parent
3c4d84db5c
commit
a9d80ddf24
1 changed files with 8 additions and 2 deletions
|
@ -153,6 +153,12 @@ const tmdbHeaders = {
|
||||||
Authorization: `Bearer ${apiKey}`,
|
Authorization: `Bearer ${apiKey}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function abortOnTimeout(timeout: number): AbortSignal {
|
||||||
|
const controller = new AbortController();
|
||||||
|
setTimeout(() => controller.abort(), timeout);
|
||||||
|
return controller.signal;
|
||||||
|
}
|
||||||
|
|
||||||
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");
|
||||||
try {
|
try {
|
||||||
|
@ -162,7 +168,7 @@ async function get<T>(url: string, params?: object): Promise<T> {
|
||||||
params: {
|
params: {
|
||||||
...params,
|
...params,
|
||||||
},
|
},
|
||||||
signal: AbortSignal.timeout(5000),
|
signal: abortOnTimeout(5000),
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return mwFetch<T>(encodeURI(url), {
|
return mwFetch<T>(encodeURI(url), {
|
||||||
|
@ -171,7 +177,7 @@ async function get<T>(url: string, params?: object): Promise<T> {
|
||||||
params: {
|
params: {
|
||||||
...params,
|
...params,
|
||||||
},
|
},
|
||||||
signal: AbortSignal.timeout(30000),
|
signal: abortOnTimeout(30000),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue