mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 11:37:49 +01:00
add fetchWithRetry
This commit is contained in:
parent
737da26f6f
commit
fec30d4d92
1 changed files with 14 additions and 2 deletions
|
@ -87,10 +87,22 @@ class InnerTubePokeVidious {
|
|||
|
||||
let desc = "";
|
||||
|
||||
const fetchWithRetry = async (url, options = {}, retries = 3) => {
|
||||
for (let attempt = 0; attempt < retries; attempt++) {
|
||||
const res = await fetch(url, options);
|
||||
if (res.status === 500 && attempt < retries - 1) {
|
||||
continue; // retry on 500
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// If all retries fail, return last response
|
||||
return null;
|
||||
};
|
||||
|
||||
try {
|
||||
const [invComments, videoInfo, videoData] = await Promise.all([
|
||||
fetch(`${this.config.invapi}/comments/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
||||
fetch(`${this.config.invapi}/videos/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
||||
fetchWithRetry(`${this.config.invapi}/comments/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
||||
fetchWithRetry(`${this.config.invapi}/videos/${v}?hl=${contentlang}®ion=${contentregion}&h=${btoa(Date.now())}`).then((res) => res.text()),
|
||||
curly
|
||||
.get(`${this.config.tubeApi}video?v=${v}`, {
|
||||
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`),
|
||||
|
|
Loading…
Reference in a new issue