mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-10 09:38:25 +01:00
does this work idk qwq
This commit is contained in:
parent
3f2576c83c
commit
2c52963c84
1 changed files with 13 additions and 3 deletions
|
@ -47,7 +47,15 @@ const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.vi
|
||||||
const { fetch } = await import("undici");
|
const { fetch } = await import("undici");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var engagementP = await fetch(apiUrl).then((res) => res.json());
|
// Set a timeout of 2 seconds.
|
||||||
|
const timeoutMilliseconds = 2000; // 2 seconds
|
||||||
|
var engagementP = await fetch(apiUrl, { timeout: timeoutMilliseconds })
|
||||||
|
.then((res) => {
|
||||||
|
if (res.statusCode === 504) {
|
||||||
|
throw new Error("Request timed out.");
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
});
|
||||||
|
|
||||||
if (typeof engagementP.dislikes === 'number') {
|
if (typeof engagementP.dislikes === 'number') {
|
||||||
return engagementP;
|
return engagementP;
|
||||||
|
@ -55,10 +63,12 @@ try {
|
||||||
throw new Error("API response doesn't contain valid dislikes count. Using fallback URL.");
|
throw new Error("API response doesn't contain valid dislikes count. Using fallback URL.");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
var engagement = await fetch(fallbackUrl).then((res) => res.json());
|
var engagement = await fetch(fallbackUrl).then((res) => res.json());
|
||||||
return engagement;
|
return engagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue