This commit is contained in:
Flummi
2020-04-06 22:15:26 +02:00
parent 8b9824e5fa
commit 3afd63b86a
6 changed files with 27 additions and 31 deletions

View File

@ -1,22 +1,12 @@
import router from "../router.mjs";
import cfg from "../../../config.json";
import fs from "fs";
import path from "path";
import url from "url";
import sql from "../sql.mjs";
import lib from "../lib.mjs";
import tpl from "../tpl.mjs";
const templates = {
contact: fs.readFileSync("./views/contact.html", "utf-8"),
how: fs.readFileSync("./views/how.html", "utf-8"),
index: fs.readFileSync("./views/index.html", "utf-8"),
item: fs.readFileSync("./views/item.html", "utf-8"),
snippets: {
navbar: fs.readFileSync("./views/snippets/navbar.html", "utf-8")
}
};
tpl.snippets = templates.snippets;
tpl.readdir("views");
router.get("/", async (req, res) => {
const query = await sql.query("select id, mime from items order by id desc limit 300");
@ -25,7 +15,7 @@ router.get("/", async (req, res) => {
last: query[query.length - 1].id
};
res.reply({ body: tpl.render(templates.index, data) });
res.reply({ body: tpl.render("views/index", data) });
});
router.get(/^\/([0-9]+)$/, async (req, res) => {
@ -58,11 +48,11 @@ router.get(/^\/([0-9]+)$/, async (req, res) => {
next: query[1].length ? query[1][0].id : null,
prev: query[2].length ? query[2][0].id : null
};
res.reply({ body: tpl.render(templates.item, data) });
res.reply({ body: tpl.render("views/item", data) });
});
router.get(/^\/(contact|help|how)$/, (req, res) => {
res.reply({ body: tpl.render(templates[req.url.split[0]]) });
res.reply({ body: tpl.render(`views/${req.url.split[0]}`) });
});
router.get("/random", async (req, res) => {