aboutsummaryrefslogtreecommitdiff
path: root/api/v1.js
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-05-10 12:25:35 +0200
committerHampusM <hampus@hampusmat.com>2021-05-10 12:25:35 +0200
commit94d26ec2a5270ca19f2e32a8381fd6e1b152c3cd (patch)
tree99729ab8cc39462ab2a9408299d6dea5d1d5c93e /api/v1.js
parent16778756fb25808a1311403590cd7d36fbbeee6c (diff)
Added a commit api endpoint & cleaned up a little
Diffstat (limited to 'api/v1.js')
-rw-r--r--api/v1.js23
1 files changed, 18 insertions, 5 deletions
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