add /version!!!

This commit is contained in:
Ashley 2022-11-15 17:40:40 +01:00
parent 4bbbb14541
commit 7b70ecf662

View file

@ -1,4 +1,13 @@
const { fetcher,core, wiki,musicInfo, modules, version, initlog, init,} = require("../libpoketube-initsys.js"); const {
fetcher,
core,
wiki,
musicInfo,
modules,
version,
initlog,
init,
} = require("../libpoketube-initsys.js");
const { const {
IsJsonString, IsJsonString,
convert, convert,
@ -9,107 +18,123 @@ const {
getRandomArbitrary, getRandomArbitrary,
} = require("../ptutils/libpt-coreutils.js"); } = require("../ptutils/libpt-coreutils.js");
module.exports = function (app, config, renderTemplate) { const pkg = require("../../../package.json");
app.get("/embed/:v", async function (req, res) {
var e = req.query.e;
var f = req.query.f;
var t = req.query.t;
var q = req.query.quality;
var v = req.params.v;
var fetching = await fetcher(v); module.exports = function (app, config, renderTemplate) {
const video = await modules.fetch(config.tubeApi + `video?v=${v}`); app.get("/embed/:v", async function (req, res) {
var e = req.query.e;
var f = req.query.f;
var t = req.query.t;
var q = req.query.quality;
var v = req.params.v;
const json = fetching.video.Player; var fetching = await fetcher(v);
const h = await video.text(); const video = await modules.fetch(config.tubeApi + `video?v=${v}`);
const k = JSON.parse(modules.toJson(h));
const engagement = fetching.engagement;
if (!v) res.redirect("/"); const json = fetching.video.Player;
const h = await video.text();
const k = JSON.parse(modules.toJson(h));
const engagement = fetching.engagement;
//video if (!v) res.redirect("/");
if (!q) url = `https://tube.kuylar.dev/proxy/media/${v}/22`;
if (q === "medium") {
var url = `https://tube.kuylar.dev/proxy/media/${v}/18`;
}
renderTemplate(res, req, "poketube-iframe.ejs", { //video
video: json, if (!q) url = `https://tube.kuylar.dev/proxy/media/${v}/22`;
url: url, if (q === "medium") {
sha384: modules.hash, var url = `https://tube.kuylar.dev/proxy/media/${v}/18`;
qua: q, }
engagement: engagement,
k: k, renderTemplate(res, req, "poketube-iframe.ejs", {
optout: t, video: json,
t: config.t_url, url: url,
sha384: modules.hash,
qua: q,
engagement: engagement,
k: k,
optout: t,
t: config.t_url,
});
}); });
});
app.get("/api/search", async (req, res) => {
const query = req.query.query;
app.get("/api/search", async (req, res) => { if (!query) {
const query = req.query.query; return res.redirect("/");
}
return res.redirect(`/search?query=${query}`);
});
if (!query) { app.get("/api/video/download", async function (req, res) {
return res.redirect("/"); var v = req.query.v;
}
return res.redirect(`/search?query=${query}`);
});
app.get("/api/video/download", async function (req, res) { var format = "mp4";
var v = req.query.v; var q = "22";
if (req.query.q) q = req.query.q;
if (req.query.f) {
var format = "mp3";
}
var fetching = await fetcher(v);
var format = "mp4"; const json = fetching.video.Player;
var q = "22";
if (req.query.q) q = req.query.q;
if (req.query.f) {
var format = "mp3";
}
var fetching = await fetcher(v);
const json = fetching.video.Player; const url = `https://tube.kuylar.dev/proxy/download/${v}/${q}/${json.Title}.${format}`;
const url = `https://tube.kuylar.dev/proxy/download/${v}/${q}/${json.Title}.${format}`; res.redirect(url);
});
res.redirect(url); app.get("/api/video/downloadjson", async function (req, res) {
}); var v = req.query.v;
var fetching = await fetcher(v);
const url = fetching.video.Player.Formats.Format[1].URL;
res.json(url);
});
app.get("/api/video/downloadjson", async function (req, res) { app.get("/api/subtitles", async (req, res) => {
var v = req.query.v; const id = req.query.v;
var fetching = await fetcher(v); const l = req.query.h;
const url = fetching.video.Player.Formats.Format[1].URL;
res.json(url);
});
app.get("/api/subtitles", async (req, res) => { const url = `https://tube.kuylar.dev/proxy/caption/${id}/${l}/`;
const id = req.query.v;
const l = req.query.h;
const url = `https://tube.kuylar.dev/proxy/caption/${id}/${l}/`; let f = await modules.fetch(url);
const body = await f.text();
let f = await modules.fetch(url); res.send(body);
const body = await f.text(); });
res.send(body); app.get("/api/redirect", async (req, res) => {
}); const red_url = req.query.u;
app.get("/api/redirect", async (req, res) => { if (!red_url) {
const red_url = req.query.u; res.redirect("/");
}
if (!red_url) { res.redirect(red_url);
res.redirect("/"); });
}
res.redirect(red_url); app.get("/api/version.json", async (req, res) => {
}); const response = {
pt_version: "v22.1115-abU9-stable",
packages: {
libpt: version,
node: process.version,
v8: process.versions.v8,
},
process: process.versions,
dependencies: pkg.dependencies,
};
app.get("/api/opensearch", async (req, res) => { res.json(response);
res.sendFile(__dirname + `/opensearch.xml`); });
});
app.get("/api/instances.json", async (req, res) => { app.get("/api/instances.json", async (req, res) => {
res.sendFile(__dirname + `/instances.json`); const url = `https://codeberg.org/Ashley/poketube/raw/branch/main/instances.json`;
});
} let f = await modules
.fetch(url)
.then((res) => res.text())
.then((json) => JSON.parse(json));
res.json(f);
});
};