mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-10 12:38:26 +01:00
Update server.js
This commit is contained in:
parent
9e64ed6be5
commit
1a32a385c3
1 changed files with 18 additions and 1 deletions
17
server.js
17
server.js
|
@ -29,9 +29,12 @@ const fetcher = require("./src/fetcher.js");
|
||||||
const templateDir = path.resolve(`${process.cwd()}${path.sep}html`);
|
const templateDir = path.resolve(`${process.cwd()}${path.sep}html`);
|
||||||
|
|
||||||
var express = require("express");
|
var express = require("express");
|
||||||
|
var useragent = require("express-useragent");
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
app.engine("html", require("ejs").renderFile);
|
app.engine("html", require("ejs").renderFile);
|
||||||
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
||||||
|
app.use(useragent.express());
|
||||||
|
|
||||||
app.set("view engine", "html");
|
app.set("view engine", "html");
|
||||||
const renderTemplate = async (res, req, template, data = {}) => {
|
const renderTemplate = async (res, req, template, data = {}) => {
|
||||||
|
@ -103,6 +106,12 @@ app.get("/mobile", async function (req, res) {
|
||||||
const lyrics = await lyricsFinder(json.Title);
|
const lyrics = await lyricsFinder(json.Title);
|
||||||
if (lyrics == undefined) lyrics = "Lyrics not found";
|
if (lyrics == undefined) lyrics = "Lyrics not found";
|
||||||
|
|
||||||
|
// redirect to pc version
|
||||||
|
|
||||||
|
if(!req.useragent.isMobile){
|
||||||
|
res.redirect(`/watch?v=${v}`);
|
||||||
|
}
|
||||||
|
|
||||||
renderTemplate(res, req, "poketube-mobile.ejs", {
|
renderTemplate(res, req, "poketube-mobile.ejs", {
|
||||||
url: url,
|
url: url,
|
||||||
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()),
|
||||||
|
@ -159,6 +168,13 @@ app.get("/watch", async function (req, res) {
|
||||||
const lyrics = await lyricsFinder(json.Title);
|
const lyrics = await lyricsFinder(json.Title);
|
||||||
if (lyrics == undefined) lyrics = "Lyrics not found";
|
if (lyrics == undefined) lyrics = "Lyrics not found";
|
||||||
|
|
||||||
|
|
||||||
|
// redirect to mobile version
|
||||||
|
if(req.useragent.isMobile){
|
||||||
|
res.redirect(`/mobile?v=${v}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
renderTemplate(res, req, "poketube.ejs", {
|
renderTemplate(res, req, "poketube.ejs", {
|
||||||
url: url,
|
url: url,
|
||||||
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()),
|
||||||
|
@ -340,3 +356,4 @@ app.get("*", function (req, res) {
|
||||||
// listen
|
// listen
|
||||||
|
|
||||||
app.listen("3000", () => {});
|
app.listen("3000", () => {});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue