mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 23:57:50 +01:00
does this work idk qwq
This commit is contained in:
parent
bfbf1fc795
commit
aac34995fd
1 changed files with 15 additions and 8 deletions
|
@ -47,9 +47,7 @@ const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.v
|
|||
const { fetch } = await import("undici");
|
||||
|
||||
try {
|
||||
// Set a timeout of 2 seconds.
|
||||
const timeoutMilliseconds = 2000; // 2 seconds
|
||||
var engagementP = await fetch(fallbackUrl, { timeout: timeoutMilliseconds })
|
||||
var engagementP = await fetch(apiUrl)
|
||||
.then((res) => {
|
||||
if (res.statusCode === 504) {
|
||||
throw new Error("Request timed out.");
|
||||
|
@ -60,12 +58,21 @@ try {
|
|||
if (typeof engagementP.dislikes === 'number') {
|
||||
return engagementP;
|
||||
} else {
|
||||
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.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
var engagement = await fetch(apiUrl).then((res) => res.json());
|
||||
|
||||
// Check the status of the fallback URL response.
|
||||
var fallbackResponse = await fetch(fallbackUrl);
|
||||
|
||||
if (fallbackResponse.statusCode === 200) {
|
||||
var engagement = await fallbackResponse.json();
|
||||
return engagement;
|
||||
} else {
|
||||
console.error("Fallback URL also failed. Returning error.");
|
||||
throw new Error("Both API and fallback URL requests failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue