mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 17:58:17 +01:00
add cachefixer
This commit is contained in:
parent
f435cfe7fe
commit
572cfcaf2b
1 changed files with 8 additions and 20 deletions
|
@ -9,7 +9,7 @@
|
||||||
/**
|
/**
|
||||||
* A class representing a PokeTube API instance for a specific video.
|
* A class representing a PokeTube API instance for a specific video.
|
||||||
*/
|
*/
|
||||||
class PokeTubeDislikesAPIManager {
|
class PokeTubeDislikesAPIManager {
|
||||||
/**
|
/**
|
||||||
* Creates a new PokeTube API instance for the given video ID.
|
* Creates a new PokeTube API instance for the given video ID.
|
||||||
* @param {string} videoId - The ID of the YouTube video.
|
* @param {string} videoId - The ID of the YouTube video.
|
||||||
|
@ -41,24 +41,12 @@ class PokeTubeDislikesAPIManager {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _getEngagementData() {
|
async _getEngagementData() {
|
||||||
const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.videoId}`;
|
const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.videoId}&cachefixer=${btoa(Date.now())}`;
|
||||||
|
|
||||||
const { fetch } = await import("undici");
|
const { fetch } = await import("undici");
|
||||||
|
|
||||||
// why RYD? why... do i have to this lol?
|
const engagement = await fetch(fallbackUrl).then((res) => res.json());
|
||||||
for (let i = 0; i < 2; i++) {
|
return engagement;
|
||||||
try {
|
|
||||||
const engagement = await fetch(fallbackUrl).then((res) => res.json());
|
|
||||||
return engagement;
|
|
||||||
} catch (err) {
|
|
||||||
if (err.status === 503) {
|
|
||||||
// retry after a bit
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
||||||
} else {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +58,7 @@ class PokeTubeDislikesAPIManager {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
engagement: this.engagement,
|
engagement: this.engagement,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue