cool stuff :3

This commit is contained in:
ashley 2025-09-01 22:30:15 +02:00
parent 828bace6d2
commit 983f0bee1f

View File

@ -58,45 +58,39 @@ class InnerTubePokeVidious {
"User-Agent": this.useragent, "User-Agent": this.useragent,
}; };
const fetchWithRetry = async (url, options = {}, retries = 3) => { const fetchWithRetry = async (url, options = {}, retries = 3) => {
let lastError; let lastError;
for (let attempt = 0; attempt < retries; attempt++) {
try {
const res = await fetch(url, {
...options,
headers: {
...options.headers,
...headers,
},
});
for (let attempt = 0; attempt < retries; attempt++) { if (res.ok) {
try { return res;
const res = await fetch(url, { }
...options,
headers: {
...options.headers,
...headers,
},
});
// If success, return immediately if ((res.status >= 500 || res.status === 429) && attempt < retries - 1) {
if (res.ok) { this.initError(`Retrying fetch for ${url}`, res.status);
return res; continue;
}
return res;
} catch (err) {
lastError = err;
this.initError(`Fetch error for ${url}`, err);
if (attempt < retries - 1) {
continue;
} else {
throw lastError;
}
}
} }
};
// If error but retryable
if ((res.status >= 500 || res.status === 429) && attempt < retries - 1) {
this.initError(`Retrying fetch for ${url}`, res.status);
continue;
}
// If non-retryable error, return response
return res;
} catch (err) {
lastError = err;
this.initError(`Fetch error for ${url}`, err);
if (attempt < retries - 1) {
continue;
} else {
throw lastError;
}
}
}
};
try { try {
const [invComments, videoInfo] = await Promise.all([ const [invComments, videoInfo] = await Promise.all([
@ -123,18 +117,6 @@ class InnerTubePokeVidious {
}; };
} }
let p = {};
if (f === "true" && vid?.authorId) {
try {
const uploads = await fetchWithRetry(
`${this.config.invapi}/channels/${vid.authorId}?hl=${contentlang}&region=${contentregion}`
);
p = this.getJson(await uploads.text());
} catch (err) {
this.initError("Failed to fetch channel uploads", err);
}
}
if (this.checkUnexistingObject(vid)) { if (this.checkUnexistingObject(vid)) {
let fe = { engagement: null }; let fe = { engagement: null };
try { try {
@ -161,7 +143,7 @@ class InnerTubePokeVidious {
result: { result: {
vid, vid,
comments, comments,
channel_uploads: p, channel_uploads: " ",
engagement: fe.engagement, engagement: fe.engagement,
wiki: "", wiki: "",
desc: "", desc: "",
@ -174,7 +156,6 @@ class InnerTubePokeVidious {
return this.cache[v].result; return this.cache[v].result;
} else { } else {
this.initError("Invalid video object (missing authorId)", vid); this.initError("Invalid video object (missing authorId)", vid);
} }
} catch (error) { } catch (error) {
this.initError("Error getting video", error); this.initError("Error getting video", error);