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 {
IsJsonString,
convert,
@ -9,10 +18,10 @@ const {
getRandomArbitrary,
} = require("../ptutils/libpt-coreutils.js");
module.exports = function (app, config, renderTemplate) {
const pkg = require("../../../package.json");
app.get("/embed/:v", async function (req, res) {
module.exports = function (app, config, renderTemplate) {
app.get("/embed/:v", async function (req, res) {
var e = req.query.e;
var f = req.query.f;
var t = req.query.t;
@ -45,19 +54,18 @@ app.get("/embed/:v", async function (req, res) {
optout: t,
t: config.t_url,
});
});
});
app.get("/api/search", async (req, res) => {
app.get("/api/search", async (req, res) => {
const query = req.query.query;
if (!query) {
return res.redirect("/");
}
return res.redirect(`/search?query=${query}`);
});
});
app.get("/api/video/download", async function (req, res) {
app.get("/api/video/download", async function (req, res) {
var v = req.query.v;
var format = "mp4";
@ -73,16 +81,16 @@ app.get("/api/video/download", async function (req, res) {
const url = `https://tube.kuylar.dev/proxy/download/${v}/${q}/${json.Title}.${format}`;
res.redirect(url);
});
});
app.get("/api/video/downloadjson", async function (req, res) {
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/subtitles", async (req, res) => {
app.get("/api/subtitles", async (req, res) => {
const id = req.query.v;
const l = req.query.h;
@ -92,9 +100,9 @@ app.get("/api/subtitles", async (req, res) => {
const body = await f.text();
res.send(body);
});
});
app.get("/api/redirect", async (req, res) => {
app.get("/api/redirect", async (req, res) => {
const red_url = req.query.u;
if (!red_url) {
@ -102,14 +110,31 @@ app.get("/api/redirect", async (req, res) => {
}
res.redirect(red_url);
});
});
app.get("/api/opensearch", async (req, res) => {
res.sendFile(__dirname + `/opensearch.xml`);
});
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/instances.json", async (req, res) => {
res.sendFile(__dirname + `/instances.json`);
});
res.json(response);
});
}
app.get("/api/instances.json", async (req, res) => {
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);
});
};