aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-06-02 20:11:59 +0200
committerHampusM <hampus@hampusmat.com>2021-06-02 20:11:59 +0200
commit094de489fcbcbe21fdd6ab89deae09af625a7f7b (patch)
tree57d490d11c4c05c71437f46df0480db4be73a5bc /src
parent13eec8a1b55cc2b64ff3125829bb69f59e03814e (diff)
The tree route optionally gets path from query param & has error handling
Diffstat (limited to 'src')
-rw-r--r--src/api/v1.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/api/v1.js b/src/api/v1.js
index 743be09..25a8019 100644
--- a/src/api/v1.js
+++ b/src/api/v1.js
@@ -113,8 +113,18 @@ module.exports = function (fastify, opts, done)
path: "/tree",
handler: async (req, reply) =>
{
- const tree = await git.getTree(opts.config.settings.base_dir, req.params.repo);
+ const tree_path = (req.query.length !== 0 && req.query.path) ? req.query.path : null;
+ const tree = await git.getTree(opts.config.settings.base_dir, req.params.repo, tree_path);
+
+ if(tree.error) {
+ if(tree.error === 404) {
+ reply.code(404).send({ error: "Path not found" });
+ }
+ else {
+ reply.code(500).send({ error: "Internal server error" });
+ }
+ }
reply.send({ data: tree });
}
});