mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-23 03:57:48 +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");
|
const { fetch } = await import("undici");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Set a timeout of 2 seconds.
|
var engagementP = await fetch(apiUrl)
|
||||||
const timeoutMilliseconds = 2000; // 2 seconds
|
|
||||||
var engagementP = await fetch(fallbackUrl, { timeout: timeoutMilliseconds })
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.statusCode === 504) {
|
if (res.statusCode === 504) {
|
||||||
throw new Error("Request timed out.");
|
throw new Error("Request timed out.");
|
||||||
|
@ -60,12 +58,21 @@ try {
|
||||||
if (typeof engagementP.dislikes === 'number') {
|
if (typeof engagementP.dislikes === 'number') {
|
||||||
return engagementP;
|
return engagementP;
|
||||||
} else {
|
} 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) {
|
} catch (error) {
|
||||||
console.error(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;
|
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