Added deploy router

Also some restructure to save code
master
Felix Stupp 6 years ago
parent 618f0b7fa0
commit 03da1f44a4

@ -6,6 +6,7 @@ let express = require("express");
let db = require("../libs/Database").instance();
let router = express.Router();
let userRouter = express.Router();
let deployRouter = express.Router();
function combineToList(a, b) {
return a + "\n" + b;
@ -15,11 +16,12 @@ function toList(array) {
return array.reduce(combineToList, "").trim();
}
router.use(["/user", "/users", "/userKeys"], userRouter);
router.use(["/u", "/user", "/users", "/userKeys"], userRouter);
router.use(["/d", "/deploy", "/deployKeys"], deployRouter);
function userReq(req, res) {
function keyReq(table, req, res) {
let p = req.params;
let q = db.q.from("sshUserKeys").select("publicKeyComment");
let q = db.q.from(table).select("publicKeyComment");
if (p.user) q.filter("user", p.user);
if (p.host) q.filter("host", p.host);
if (p.type) q.filter("type", p.type);
@ -39,6 +41,9 @@ function userReq(req, res) {
"/@" + host + "/" + type,
"/" + user + "/" + type,
"/" + user + "@" + host + "/" + type,
].forEach(e => userRouter.get(e, (req, res) => userReq(req, res)));
].forEach(e => {
userRouter.get(e, (req, res) => keyReq("sshUserKeys", req, res));
deployRouter.get(e, (req, res) => keyReg("sshDeployKeys", req, res));
});
module.exports = router;
Loading…
Cancel
Save