fix some issues regarding the api :3

This commit is contained in:
Ashley 2022-09-29 20:59:53 +02:00
parent 3dde711bf8
commit 12de0df326

View file

@ -177,19 +177,24 @@ app.get("/watch", async function (req, res) {
var badges = ""; var badges = "";
// try 4 times, thanks kuylar // try few times, thanks kuylar
for (let i = 0; i < 4; i++) { for (let i = 0; i < 5; i++) {
try { try {
const nightly = await fetch( const nightly = await fetch(
`https://lighttube-nightly.kuylar.dev/api/video?v=${v}` `https://lighttube-nightly.kuylar.dev/api/video?v=${v}`
); );
var n = await nightly.text(); var n = await nightly.text();
if(n == undefined) {
for(let i=0;i<3;i+=1){try{const nightly=await fetch(`https://lighttube-nightly.kuylar.dev/api/video?v=${ v }`);var n=await nightly.text()}catch(err){if(err.status===500){await new Promise((resolve)=>setTimeout(resolve,1000))}else{return(n="")}}}
}
} catch (err) { } catch (err) {
if (err.status === 503) { if (err.status === 500) {
// retry after a bit // retry after a bit
await new Promise((resolve) => setTimeout(resolve, 1000)); await new Promise((resolve) => setTimeout(resolve, 1000));
} else { } else {
return (n = "none"); return (n = "");
} }
} }
} }
@ -198,15 +203,15 @@ app.get("/watch", async function (req, res) {
var nnn = ""; var nnn = "";
var comments = ""; var comments = "";
if (n === "none") { if (n == "") {
badges, nnn, comments = ""; badges, nnn, comments = "";
} }
if (IsJsonString(n)) { if (IsJsonString(n)) {
if (n !== "none") { if (n != "") {
badges = JSON.parse(n).channel.badges[0];
nnn = JSON.parse(n); nnn = JSON.parse(n);
comments = JSON.parse(n).commentCount; badges = nnn.channel.badges[0];
comments = nnn.commentCount;
} }
} }