From 8377cd9881167dcde40f0947c623ddbb64120747 Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Sat, 10 Oct 2020 12:12:11 +0200 Subject: Some npm scripts --- motto/index.js | 76 ---------------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 motto/index.js (limited to 'motto/index.js') diff --git a/motto/index.js b/motto/index.js deleted file mode 100644 index 4a8ed3b..0000000 --- a/motto/index.js +++ /dev/null @@ -1,76 +0,0 @@ -const express = require("express"); -const rateLimit = require("express-rate-limit"); -const db = require("../db"); -const app = express.Router(); - -const apiLimiter = rateLimit({ - windowMs: 10 * 60 * 1000, - max: 100, - message: "Access overflow!", -}); - -//const fs = require("fs"); -//app.get("/sync", (req, res) => { -// fs.readFile(__dirname + "/list.txt", "utf8", (err, data) => { -// if (err) { -// console.error(err); -// return res.send("error"); -// } -// const lines = data.split("\n"); -// lines.forEach(async (line) => { -// const split = line.split(" - "); -// try { -// if (split.length >= 2) -// await db.query("INSERT INTO theme (main, description) VALUES (?, ?)", split.slice(0, 2)); -// else console.log(line); -// } catch (e) { -// console.error(e); -// } -// }); -// res.send("ok"); -// }); -//}); - -app.use("/", express.static(__dirname + "/public")); - -app.use("/api/", apiLimiter); - -app.get("/api/list", async (req, res) => { - try { - const themes = await db.query("SELECT * FROM theme WHERE hidden = FALSE ORDER BY votes DESC"); - res.json(themes); - } catch (e) { - console.error(e); - res.send("error"); - } -}); - -app.post("/api/add", async (req, res) => { - console.log(req.body.main, req.body.description); - if (!req.body.main || !req.body.description) return res.send("error"); - try { - await db.query("INSERT INTO theme (main, description) VALUES (?, ?)", [req.body.main, req.body.description]); - res.send("ok"); - } catch (e) { - console.error(e); - res.send("error"); - } -}); - -app.post("/api/vote", async (req, res) => { - console.log(req.body.id, req.body.vote); - if (req.body.vote < -1 || req.body.vote > 1) { - res.send("error"); - return; - } - - try { - await db.query("UPDATE theme SET votes = votes + ? WHERE id = ?", [req.body.vote, req.body.id]); - res.send("ok"); - } catch (e) { - console.error(e); - res.send("error"); - } -}); - -module.exports = app; -- cgit v1.2.3