From 94d26ec2a5270ca19f2e32a8381fd6e1b152c3cd Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 10 May 2021 12:25:35 +0200 Subject: Added a commit api endpoint & cleaned up a little --- api/v1.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'api/v1.js') diff --git a/api/v1.js b/api/v1.js index 7358d3b..4987ba7 100644 --- a/api/v1.js +++ b/api/v1.js @@ -24,12 +24,17 @@ router.get("/repos", async function(req, res) res.json({ "data": repos }); }); -router.get("/repos/:repo", async function(req, res) +router.use("/repos/:repo", async function(req, res, next) { if(!sanitization.sanitizeRepoName(req.params.repo)) { res.status(400).json({ "error": "Unacceptable git repository name!" }); return; } + next(); +}); + +router.get("/repos/:repo", async function(req, res) +{ const repo = `${req.params.repo}.git`; const desc = await git.getRepoFile(req.settings["base_dir"], repo, "description"); @@ -38,10 +43,6 @@ router.get("/repos/:repo", async function(req, res) router.get("/repos/:repo/log", async function(req, res) { - if(!sanitization.sanitizeRepoName(req.params.repo)) { - res.status(400).json({ "error": "Unacceptable git repository name!" }); - return; - } const repo = `${req.params.repo}.git`; const log = await git.getLog(req.settings["base_dir"], repo); @@ -60,4 +61,16 @@ router.get("/repos/:repo/log", async function(req, res) res.json(log); }); +router.get("/repos/:repo/log/:commit", async function(req, res) +{ + if(!sanitization.sanitizeCommitID(req.params.commit)) { + res.status(400).json({ "error": "Unacceptable commit id!" }); + return; + } + + const commit = await git.getCommit(req.settings["base_dir"], req.params.repo, req.params.commit); + + res.json(commit); +}); + module.exports = router; \ No newline at end of file -- cgit v1.2.3-18-g5258