From 3f2576c83cb3f2906e829b1aad58512f12f81eff Mon Sep 17 00:00:00 2001 From: Ashley Date: Sat, 21 Oct 2023 05:10:02 +0000 Subject: [PATCH] this is one of the commits ever lol --- src/libpoketube/libpoketube-dislikes.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/libpoketube/libpoketube-dislikes.js b/src/libpoketube/libpoketube-dislikes.js index c2a728c1..197dcd89 100644 --- a/src/libpoketube/libpoketube-dislikes.js +++ b/src/libpoketube/libpoketube-dislikes.js @@ -41,20 +41,25 @@ class PokeTubeDislikesAPIManager { * @private */ async _getEngagementData() { - const apiUrl = `https://p.poketube.fun/api?v=${this.videoId}&hash=d0550b6e28c8f93533a569c314d5b4e2`; - const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.videoId}`; + const apiUrl = `https://p.poketube.fun/api?v=${this.videoId}&hash=d0550b6e28c8f93533a569c314d5b4e2`; +const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.videoId}`; - const { fetch } = await import("undici"); +const { fetch } = await import("undici"); - var engagementP = await fetch(apiUrl).then((res) => res.json()); +try { + var engagementP = await fetch(apiUrl).then((res) => res.json()); - if(!engagementP.dislikes) { - var engagement = await fetch(fallbackUrl).then((res) => res.json()); - return engagement; - } else { - return engagementP; - } + if (typeof engagementP.dislikes === 'number') { + return engagementP; + } else { + throw new Error("API response doesn't contain valid dislikes count. Using fallback URL."); } +} catch (error) { + var engagement = await fetch(fallbackUrl).then((res) => res.json()); + return engagement; +} + +} /**