X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=routes%2Fall.js;h=3e989f77b967f852ae53d1c05b6bf15498890911;hp=f3e184e608133d267c374f6b4c0360c1c8531690;hb=0bd5933d97a90473233d0f90f465a43aba430ffa;hpb=da06a6eb0237123ce43fdb01cb06246b8b57f5e5 diff --git a/routes/all.js b/routes/all.js index f3e184e6..3e989f77 100644 --- a/routes/all.js +++ b/routes/all.js @@ -1,78 +1,11 @@ -let express = require('express'); -let router = express.Router(); -const createError = require('http-errors'); -const sqlite3 = require('sqlite3');//.verbose(); -const db = new sqlite3.Database('db/vchess.sqlite'); -const sanitizeHtml = require('sanitize-html'); - -// Home -router.get('/', function(req, res, next) { - db.serialize(function() { - db.all("SELECT * FROM Variants", (err,variants) => { - if (!!err) - return next(err); - res.render('index', { - title: 'club', - variantArray: variants, //JSON.stringify(variants) - }); - }); - }); -}); - -// Variant -router.get("/:vname([a-zA-Z0-9]+)", (req,res,next) => { - const vname = req.params["vname"]; - db.serialize(function() { - db.all("SELECT * FROM Variants WHERE name='" + vname + "'", (err,variant) => { - if (!!err) - return next(err); - if (!variant || variant.length==0) - return next(createError(404)); - db.all("SELECT * FROM Problems WHERE variant='" + vname + "'", - (err2,problems) => { - if (!!err2) - return next(err2); - res.render('variant', { - title: vname + ' Variant', - variant: vname, - problemArray: problems, - }); - } - ); - }); - }); -}); - -// Load a rules page (AJAX) -router.get("/rules/:variant([a-zA-Z0-9]+)", (req,res) => { - if (!req.xhr) - return res.json({errmsg: "Unauthorized access"}); - res.render("rules/" + req.params["variant"]); -}); - -// Fetch 10 previous or next problems (AJAX) -router.get("/problems/:variant([a-zA-Z0-9]+)", (req,res) => { - if (!req.xhr) - return res.json({errmsg: "Unauthorized access"}); - // TODO: next or previous: in params + timedate (of current oldest or newest) -}); - -// Upload a problem (AJAX) -router.post("/problems/:variant([a-zA-Z0-9]+)", (req,res) => { - if (!req.xhr) - return res.json({errmsg: "Unauthorized access"}); - const vname = req.params["variant"]; - - // TODO: get parameters and sanitize them - sanitizeHtml(req.body["fen"]); // [/a-z0-9 ]* - sanitizeHtml(req.body["instructions"]); - db.serialize(function() { - let stmt = db.prepare("INSERT INTO Problems VALUES (?,?,?,?,?)"); - stmt.run(timestamp, vname, fen, instructions, solution); - stmt.finalize(); - }); - res.json({}); -}); - +var router = require("express").Router(); + +router.use("/", require("./index")); +router.use("/", require("./users")); +router.use("/", require("./problems")); +router.use("/", require("./messages")); +//router.use("/", require("./challenge")); +//router.use("/", require("./playing")); +router.use("/", require("./variant")); module.exports = router;