1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
const express = require("express");
const git = require("./git");
const sanitization = require("./sanitization");
const router = express.Router();
router.get("/info", function(req, res)
{
res.json({ "data": req.settings });
return;
});
router.get("/repos", async function(req, res)
{
let repo_dirs = await git.getRepos(req.settings["base_dir"]);
if(repo_dirs["error"]) {
res.status(500).send("Internal server error!");
return;
}
repo_dirs = repo_dirs["data"].filter(repo => repo.endsWith(".git"));
const repos = await git.getBasicRepoInfo(req.settings["base_dir"], repo_dirs);
res.json({ "data": repos });
});
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");
res.json({ "data": { "name": req.params.repo, "description": desc } });
});
router.get("/repos/:repo/log", async function(req, res)
{
const repo = `${req.params.repo}.git`;
const log = await git.getLog(req.settings["base_dir"], repo);
if(log["error"]) {
if(typeof log["error"] === "string") {
res.status(500).json({ "error": log["error"] });
return;
}
switch(log["error"]) {
case 404:
res.status(404).json({ "error": "Git repository doesn't exist!" });
return;
}
return;
}
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;
|