diff options
author | HampusM <hampus@hampusmat.com> | 2021-05-24 10:49:41 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-05-24 10:49:41 +0200 |
commit | 518bd58c5aba1a6eaa645074f3ae2d780c45f6dc (patch) | |
tree | a99acd3b434422e019bc76064ad0798c8472f07d /api/v1.js | |
parent | 21e52ba2fa323e8aebf291882083c1eca9f6a5af (diff) |
Restructured the whole project & added Nodemon and Concurrently
Diffstat (limited to 'api/v1.js')
-rw-r--r-- | api/v1.js | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/api/v1.js b/api/v1.js deleted file mode 100644 index 7920afc..0000000 --- a/api/v1.js +++ /dev/null @@ -1,74 +0,0 @@ -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 repos = await git.getRepos(req.settings["base_dir"]); - - if(repos["error"]) { - res.status(500).send("Internal server error!"); - return; - } - - 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({ data: 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({ data: commit }); -}); - -module.exports = router;
\ No newline at end of file |