reformat file

This commit is contained in:
Ashley 2022-09-29 21:15:42 +02:00
parent 99501793c2
commit 84f8759522

View file

@ -93,8 +93,8 @@ function IsJsonString(str) {
}
function convert(value) {
return new Intl.NumberFormat('en-GB', {
notation: "compact"
return new Intl.NumberFormat("en-GB", {
notation: "compact",
}).format(value);
}
@ -104,7 +104,6 @@ function getFirstLine(text) {
return text.substring(0, index);
}
/////////////////////////////////
app.use(function (req, res, next) {
@ -178,17 +177,28 @@ app.get("/watch", async function (req, res) {
var badges = "";
// try few times, thanks kuylar
for (let i = 0; i < 5; i++) {
for (let i = 0; i < 3; 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="")}}}
for (let i = 0; i < 6; i++) {
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 === 500) {
// retry after a bit
@ -204,7 +214,7 @@ app.get("/watch", async function (req, res) {
var comments = "";
if (n == "") {
badges, nnn, comments = "";
badges, nnn, (comments = "");
}
if (IsJsonString(n)) {
@ -297,7 +307,9 @@ app.get("/watch", async function (req, res) {
*/
renderTemplate(res, req, "poketube.ejs", {
url: url_e,
color: await getColors( `https://i.ytimg.com/vi/${v}/maxresdefault.jpg` ).then((colors) => colors[0].hex()),
color: await getColors(
`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`
).then((colors) => colors[0].hex()),
engagement: engagement,
video: json,
date: moment(k.Video.uploadDate).format("LL"),
@ -353,8 +365,6 @@ app.get("/music", async function (req, res) {
const h = await video.text();
const k = JSON.parse(toJson(h));
if (!json.Channel.Name.endsWith(" - Topic")) {
res.redirect(`/watch?v=${v}`);
}
@ -362,7 +372,6 @@ app.get("/music", async function (req, res) {
//video
var url = `https://tube.kuylar.dev/proxy/media/${v}/18`;
// encryption
const url_e =
url +
@ -372,7 +381,6 @@ app.get("/music", async function (req, res) {
"Piwik" +
sha384(config.t_url);
// channel info
const engagement = fetching.engagement;
const channel = await fetch(
@ -471,10 +479,16 @@ app.get("/search", async (req, res) => {
const { toJson } = require("xml2json");
const query = req.query.query;
if(req.query.continuation){ var continuation = req.query.continuation }
if(!req.query.continuation){ var continuation = "" }
if (req.query.continuation) {
var continuation = req.query.continuation;
}
if (!req.query.continuation) {
var continuation = "";
}
const search = await fetch(`https://tube.kuylar.dev/api/search?query=${query}&continuation=${continuation}`);
const search = await fetch(
`https://tube.kuylar.dev/api/search?query=${query}&continuation=${continuation}`
);
const text = await search.text();
const j = JSON.parse(toJson(text));
@ -498,18 +512,20 @@ app.get("/channel/", async (req, res) => {
const h = await bout.text();
const k = JSON.parse(toJson(h));
if(req.query.continuation){ var continuation = req.query.continuation }
if(!req.query.continuation){ var continuation = "" }
if (req.query.continuation) {
var continuation = req.query.continuation;
}
if (!req.query.continuation) {
var continuation = "";
}
//videos
const channel = await fetch(config.tubeApi + `channel?id=${ID}&tab=videos&Continuation=${continuation}`);
const channel = await fetch(
config.tubeApi + `channel?id=${ID}&tab=videos&Continuation=${continuation}`
);
const c = await channel.text();
const tj = JSON.parse(toJson(c));
const summary = await wiki.summary(k.Channel.Metadata.Name);
var w = "";
@ -528,12 +544,11 @@ app.get("/channel/", async (req, res) => {
var d = "";
}
var dnoreplace = description.toString()
var dnoreplace = description.toString();
if (dnoreplace === "[object Object]") {
var dnoreplace = "";
}
renderTemplate(res, req, "channel.ejs", {
ID: ID,
tab: tab,
@ -578,7 +593,6 @@ app.get("/js/:id", (req, res) => {
res.sendFile(__dirname + `/js/${req.params.id}`);
});
///////////// API /////////////
app.get("/embed/:v", async function (req, res) {