From 99501793c2f0226185410556d3b1b39e388af204 Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 29 Sep 2022 20:59:53 +0200 Subject: [PATCH] fix some issues regarding the api :3 --- server.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index 6348ba0c..59a1ba1a 100644 --- a/server.js +++ b/server.js @@ -177,19 +177,24 @@ app.get("/watch", async function (req, res) { var badges = ""; - // try 4 times, thanks kuylar - for (let i = 0; i < 4; i++) { + // try few times, thanks kuylar + for (let i = 0; i < 5; i++) { try { const nightly = await fetch( `https://lighttube-nightly.kuylar.dev/api/video?v=${v}` ); 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) { - if (err.status === 503) { + if (err.status === 500) { // retry after a bit await new Promise((resolve) => setTimeout(resolve, 1000)); } else { - return (n = "none"); + return (n = ""); } } } @@ -198,15 +203,15 @@ app.get("/watch", async function (req, res) { var nnn = ""; var comments = ""; - if (n === "none") { + if (n == "") { badges, nnn, comments = ""; } if (IsJsonString(n)) { - if (n !== "none") { - badges = JSON.parse(n).channel.badges[0]; + if (n != "") { nnn = JSON.parse(n); - comments = JSON.parse(n).commentCount; + badges = nnn.channel.badges[0]; + comments = nnn.commentCount; } }