aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/routes/api/v1/repo/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src/routes/api/v1/repo/index.ts')
-rw-r--r--packages/server/src/routes/api/v1/repo/index.ts34
1 files changed, 33 insertions, 1 deletions
diff --git a/packages/server/src/routes/api/v1/repo/index.ts b/packages/server/src/routes/api/v1/repo/index.ts
index f5f9030..3b115d4 100644
--- a/packages/server/src/routes/api/v1/repo/index.ts
+++ b/packages/server/src/routes/api/v1/repo/index.ts
@@ -9,6 +9,7 @@ import log from "./log";
import { verifyRepoName } from "../../util";
import { Tree as APITree, Tag as APITag, TreeEntry as APITreeEntry } from "api";
import { BaseError } from "../../../../git/error";
+import { commitMap } from "./map";
declare module "fastify" {
interface FastifyRequest {
@@ -101,6 +102,37 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do
fastify.route<Route>({
method: "GET",
+ url: "/tree/history",
+ handler: async(req, reply) => {
+ const tree = await req.repository.tree().catch((err: BaseError) => err);
+
+ if(tree instanceof BaseError) {
+ reply.code(tree.code).send({ error: tree.message });
+ return;
+ }
+
+ if(Object.keys(req.query).length === 0) {
+ reply.code(400).send({ error: "Missing query parameter 'path'!" });
+ return;
+ }
+
+ const tree_path = req.query.path;
+
+ const tree_entry = await tree.find(tree_path).catch((err: BaseError) => err);
+
+ if(tree_entry instanceof BaseError) {
+ reply.code(tree_entry.code).send({ error: tree_entry.message });
+ return;
+ }
+
+ const history = await tree_entry.history();
+
+ reply.send({ data: await Promise.all(history.map(commitMap)) });
+ }
+ });
+
+ fastify.route<Route>({
+ method: "GET",
url: "/tags",
handler: async(req, reply) => {
const tags = await req.repository.tags();
@@ -111,4 +143,4 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do
});
done();
-} \ No newline at end of file
+}