does this work idk qwq

This commit is contained in:
Ashley 2023-10-21 05:18:24 +00:00
parent bfbf1fc795
commit aac34995fd

View file

@ -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.");
}
}