From 43faf0bfd5544f9338e1442ab5b1fcb3210867ac Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 22 Jun 2021 13:31:43 +0200 Subject: Refactored the backend yet again & got eslint too work with typescript --- packages/server/src/api/v1/repo/log.ts | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 packages/server/src/api/v1/repo/log.ts (limited to 'packages/server/src/api/v1/repo/log.ts') diff --git a/packages/server/src/api/v1/repo/log.ts b/packages/server/src/api/v1/repo/log.ts new file mode 100644 index 0000000..f692b00 --- /dev/null +++ b/packages/server/src/api/v1/repo/log.ts @@ -0,0 +1,40 @@ +import { FastifyInstance, FastifyPluginOptions } from "fastify"; +import { GitAPI } from "../../git"; +import { Route } from "../../../fastify_types"; +import { verifySHA } from "../../util"; + +export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, done: (err?: Error) => void): void { + const git: GitAPI = opts.config.git; + + fastify.route({ + method: "GET", + url: "/log", + handler: async(req, reply) => { + const log = await git.getLog(req.params.repo); + + if(log.length === 0) { + reply.code(500).send({ error: "Internal server error!" }); + return; + } + + reply.send({ data: log }); + } + }); + + fastify.route({ + method: "GET", + url: "/log/:commit", + handler: async(req, reply) => { + const commit_verification = await verifySHA(git, req.params.repo, req.params.commit); + if(commit_verification.success === false && commit_verification.code) { + reply.code(commit_verification.code).send({ error: commit_verification.message }); + } + + const commit = await git.getCommit(req.params.repo, req.params.commit); + + reply.send({ data: commit }); + } + }); + + done(); +} \ No newline at end of file -- cgit v1.2.3-18-g5258