2022-09-21 08:36:21 +02:00
|
|
|
/*
|
2022-07-29 14:26:00 +02:00
|
|
|
|
|
|
|
PokeTube is an Free/Libre youtube front-end. this is our main file.
|
|
|
|
|
2023-01-11 17:20:38 +01:00
|
|
|
Copyright (C) 2021-2023 POKETUBE (https://github.com/iamashley0/poketube)
|
2022-02-28 18:33:58 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see https://www.gnu.org/licenses/.
|
|
|
|
*/
|
2022-11-06 12:09:28 +01:00
|
|
|
|
2023-01-11 17:20:38 +01:00
|
|
|
(async function () {
|
|
|
|
const {
|
|
|
|
fetcher,
|
|
|
|
core,
|
|
|
|
wiki,
|
|
|
|
musicInfo,
|
|
|
|
modules,
|
|
|
|
version,
|
|
|
|
initlog,
|
|
|
|
init,
|
|
|
|
} = require("./src/libpoketube/libpoketube-initsys.js");
|
|
|
|
const media_proxy = require("./src/libpoketube/libpoketube-video.js");
|
|
|
|
const { sinit } = require("./src/libpoketube/init/superinit.js");
|
|
|
|
const u = await media_proxy();
|
|
|
|
initlog("Loading...");
|
|
|
|
initlog(
|
|
|
|
"[Welcome] Welcome To PokeTube :3 " +
|
|
|
|
"Running " +
|
|
|
|
`Node ${process.version} - V8 v${
|
|
|
|
process.versions.v8
|
|
|
|
} - ${process.platform.replace("linux", "GNU/Linux")} ${
|
|
|
|
process.arch
|
|
|
|
} Server - libpt ${version}`
|
2022-02-23 19:54:21 +01:00
|
|
|
);
|
2022-07-12 19:06:02 +02:00
|
|
|
|
2023-01-11 17:20:38 +01:00
|
|
|
const {
|
|
|
|
IsJsonString,
|
|
|
|
convert,
|
|
|
|
getFirstLine,
|
|
|
|
capitalizeFirstLetter,
|
|
|
|
turntomins,
|
|
|
|
getRandomInt,
|
|
|
|
getRandomArbitrary,
|
|
|
|
} = require("./src/libpoketube/ptutils/libpt-coreutils.js");
|
|
|
|
|
|
|
|
initlog("Loaded libpt-coreutils");
|
|
|
|
|
|
|
|
const templateDir = modules.path.resolve(
|
|
|
|
`${process.cwd()}${modules.path.sep}html`
|
|
|
|
);
|
|
|
|
|
|
|
|
const sha384 = modules.hash;
|
|
|
|
|
|
|
|
var app = modules.express();
|
|
|
|
initlog("Loaded express.js");
|
|
|
|
app.engine("html", require("ejs").renderFile);
|
|
|
|
app.use(modules.express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
|
|
|
app.use(modules.useragent.express());
|
|
|
|
app.use(modules.express.json()); // for parsing application/json
|
2023-01-12 21:11:35 +01:00
|
|
|
app.enable("trust proxy");
|
2023-01-11 17:20:38 +01:00
|
|
|
|
|
|
|
const renderTemplate = async (res, req, template, data = {}) => {
|
|
|
|
res.render(
|
|
|
|
modules.path.resolve(`${templateDir}${modules.path.sep}${template}`),
|
|
|
|
Object.assign(data)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const random_words = [
|
|
|
|
"banana pie",
|
|
|
|
"how to buy an atom bomb",
|
|
|
|
"is love just an illusion",
|
|
|
|
"things to do if ur face becomes benjamin frenklin",
|
|
|
|
"how do defeat an pasta",
|
|
|
|
"can you go to space?",
|
|
|
|
"how to become a god?",
|
|
|
|
"is a panda a panda if pandas???",
|
|
|
|
"Minecraft movie trailer",
|
|
|
|
"monke",
|
|
|
|
];
|
|
|
|
|
|
|
|
/*
|
2022-06-26 10:24:02 +02:00
|
|
|
this is our config file,you can change stuff here
|
|
|
|
*/
|
2023-01-11 17:20:38 +01:00
|
|
|
const config = {
|
2023-01-12 16:59:09 +01:00
|
|
|
tubeApi: "https://api.poketube.fun/api/",
|
2023-01-11 20:18:19 +01:00
|
|
|
invapi: "https://invidious.sethforprivacy.com/api/v1",
|
2023-01-11 17:20:38 +01:00
|
|
|
dislikes: "https://returnyoutubedislikeapi.com/votes?videoId=",
|
2023-02-09 17:32:14 +01:00
|
|
|
invchannel: "https://invidious.privacydev.net/api/v1",
|
|
|
|
cacher_max_age: "1800",
|
2023-01-13 16:33:36 +01:00
|
|
|
enablealwayshttps: true, //enables always https on the server
|
2023-01-11 17:20:38 +01:00
|
|
|
t_url: "https://t.poketube.fun/", // def matomo url
|
|
|
|
};
|
2022-08-23 14:04:34 +02:00
|
|
|
|
2023-01-11 17:20:38 +01:00
|
|
|
app.use(function (req, res, next) {
|
|
|
|
res.header("Access-Control-Allow-Origin", "*");
|
2023-01-12 21:11:35 +01:00
|
|
|
if (req.secure) {
|
|
|
|
res.header(
|
|
|
|
"Strict-Transport-Security",
|
|
|
|
"max-age=31536000; includeSubDomains; preload"
|
|
|
|
);
|
|
|
|
}
|
2023-01-20 19:15:30 +01:00
|
|
|
res.header("secure-poketube-instance", "1");
|
|
|
|
|
2023-01-12 21:11:35 +01:00
|
|
|
next();
|
|
|
|
});
|
2023-01-13 16:33:36 +01:00
|
|
|
|
2023-01-12 21:11:35 +01:00
|
|
|
app.use(function (request, response, next) {
|
2023-02-09 17:32:14 +01:00
|
|
|
if (config.enablealwayshttps && !request.secure) {
|
|
|
|
return response.redirect("https://" + request.headers.host + request.url);
|
|
|
|
}
|
2022-09-17 18:22:47 +02:00
|
|
|
|
2023-01-11 17:20:38 +01:00
|
|
|
next();
|
|
|
|
});
|
2022-12-05 18:44:37 +01:00
|
|
|
|
2023-02-06 15:23:19 +01:00
|
|
|
app.use(function (req, res, next) {
|
|
|
|
if (req.url.match(/^\/(css|js|img|font)\/.+/)) {
|
2023-02-09 17:32:14 +01:00
|
|
|
res.setHeader(
|
|
|
|
"Cache-Control",
|
|
|
|
"public, max-age=" + config.cacher_max_age
|
|
|
|
); // cache header
|
|
|
|
res.setHeader("poketube-cacher", "STATIC_FILES");
|
2023-02-06 15:23:19 +01:00
|
|
|
}
|
|
|
|
next();
|
2023-02-09 17:32:14 +01:00
|
|
|
});
|
2023-02-06 15:23:19 +01:00
|
|
|
|
2023-02-09 17:32:14 +01:00
|
|
|
initlog("[OK] Load headers")
|
|
|
|
|
|
|
|
app.get("/robots.txt", (req, res) => {
|
|
|
|
res.sendFile(__dirname + "/robots.txt");
|
|
|
|
});
|
|
|
|
|
|
|
|
initlog("[OK] Load robots.txt")
|
|
|
|
|
2023-01-11 17:20:38 +01:00
|
|
|
sinit(app, config, renderTemplate);
|
2022-09-21 08:36:21 +02:00
|
|
|
|
2023-01-11 17:20:38 +01:00
|
|
|
init(app);
|
|
|
|
})();
|