mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 23:17:57 +01:00
add better error handeling :3
This commit is contained in:
parent
fd1fead07f
commit
022d706afa
1 changed files with 13 additions and 50 deletions
|
@ -1,22 +1,5 @@
|
||||||
const {
|
const { fetcher, core, wiki, musicInfo, modules, version, initlog, init, } = require("../libpoketube-initsys.js");
|
||||||
fetcher,
|
const { IsJsonString, convert, getFirstLine, capitalizeFirstLetter, turntomins, getRandomInt, getRandomArbitrary} = require("../ptutils/libpt-coreutils.js");
|
||||||
core,
|
|
||||||
wiki,
|
|
||||||
musicInfo,
|
|
||||||
modules,
|
|
||||||
version,
|
|
||||||
initlog,
|
|
||||||
init,
|
|
||||||
} = require("../libpoketube-initsys.js");
|
|
||||||
const {
|
|
||||||
IsJsonString,
|
|
||||||
convert,
|
|
||||||
getFirstLine,
|
|
||||||
capitalizeFirstLetter,
|
|
||||||
turntomins,
|
|
||||||
getRandomInt,
|
|
||||||
getRandomArbitrary,
|
|
||||||
} = require("../ptutils/libpt-coreutils.js");
|
|
||||||
const media_proxy = require("../libpoketube-video.js");
|
const media_proxy = require("../libpoketube-video.js");
|
||||||
const atmos = require("../../../pokeatmosurls.json");
|
const atmos = require("../../../pokeatmosurls.json");
|
||||||
|
|
||||||
|
@ -182,7 +165,7 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
|
|
||||||
const isVideoValid = await core.isvalidvideo(v);
|
const isVideoValid = await core.isvalidvideo(v);
|
||||||
if (!isVideoValid) {
|
if (!isVideoValid) {
|
||||||
return res.redirect("/?fromerror=21");
|
return res.redirect("/?fromerror=21_video_not_valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
const u = await media_proxy(v);
|
const u = await media_proxy(v);
|
||||||
|
@ -192,19 +175,17 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
].includes(req.hostname);
|
].includes(req.hostname);
|
||||||
const verify = req.hostname === "pt.zzls.xyz";
|
const verify = req.hostname === "pt.zzls.xyz";
|
||||||
|
|
||||||
function linkify(text) {
|
function linkify(text) {
|
||||||
// regular expression to match URLs
|
// regular expression to match URLs
|
||||||
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||||
|
|
||||||
return text.replace(urlRegex, (url) => {
|
return text.replace(urlRegex, (url) => {
|
||||||
// wrap the URL in an <a> tag with the URL as the href attribute
|
// wrap the URL in an <a> tag with the URL as the href attribute
|
||||||
return `<a href="/api/redirect?u=${btoa(url.replace(/twitter\.com/g, "nitter.net").replace(/reddit\.com/g, "teddit.net").replace("https://youtube.com", "").replace("https://youtu.be", ""))}" target="_blank">${url}</a>`;
|
return `<a href="/api/redirect?u=${btoa(url.replace(/twitter\.com/g, "nitter.net").replace(/reddit\.com/g, "teddit.net").replace("https://youtube.com", "").replace("https://youtu.be", ""))}" target="_blank">${url}</a>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.video(v).then((data) => {
|
||||||
|
|
||||||
core.video(v).then((data) => {
|
|
||||||
try {
|
try {
|
||||||
const k = data.video;
|
const k = data.video;
|
||||||
const json = data.json;
|
const json = data.json;
|
||||||
|
@ -235,13 +216,11 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
if(inv_vid?.error === "The uploader has not made this video available in your country"){
|
if(inv_vid?.error === "The uploader has not made this video available in your country"){
|
||||||
res.send("error : " + inv_vid.error + " please refresh the page please qt ")
|
res.send("error : " + inv_vid.error + " please refresh the page please qt ")
|
||||||
}
|
}
|
||||||
if(inv_vid?.error === "This video is not available"){
|
|
||||||
|
if(inv_vid?.error === "This video is not available"){
|
||||||
res.send("error : " + inv_vid.error + " please refresh the page please qt ")
|
res.send("error : " + inv_vid.error + " please refresh the page please qt ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
renderTemplate(res, req, "poketube.ejs", {
|
renderTemplate(res, req, "poketube.ejs", {
|
||||||
color: data.color,
|
color: data.color,
|
||||||
color2: data.color2,
|
color2: data.color2,
|
||||||
|
@ -279,7 +258,7 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return res.redirect("/?fromerror=41");
|
return res.redirect("/?fromerror=41_generic_error");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -291,18 +270,7 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
const info = await modules.fetch("http://ip-api.com/json/");
|
const info = await modules.fetch("http://ip-api.com/json/");
|
||||||
const ip = await info.json();
|
const ip = await info.json();
|
||||||
|
|
||||||
const {
|
const {video: k,json,engagement,comments: inv_comments,vid: inv_vid,} = await core.video(v);
|
||||||
video: k,
|
|
||||||
json,
|
|
||||||
engagement,
|
|
||||||
comments: inv_comments,
|
|
||||||
vid: inv_vid,
|
|
||||||
} = await core.video(v);
|
|
||||||
|
|
||||||
if (!k || !json || !json.Title) {
|
|
||||||
res.redirect("/");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await core.video(v);
|
const data = await core.video(v);
|
||||||
const color = data.color;
|
const color = data.color;
|
||||||
|
@ -315,11 +283,6 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
const d = desc.toString().replace(/\n/g, " <br> ");
|
const d = desc.toString().replace(/\n/g, " <br> ");
|
||||||
const comments = inv_comments || "Disabled";
|
const comments = inv_comments || "Disabled";
|
||||||
|
|
||||||
const url =
|
|
||||||
q === "medium"
|
|
||||||
? `https://inv.vern.cc/latest_version?id=${v}&itag=18&local=true`
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const templateData = {
|
const templateData = {
|
||||||
color,
|
color,
|
||||||
color2,
|
color2,
|
||||||
|
@ -353,7 +316,7 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
renderTemplate(res, req, "lite.ejs", templateData);
|
renderTemplate(res, req, "lite.ejs", templateData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
res.redirect("/");
|
res.redirect("/?err=" + error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue