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/index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'packages/server/src/api/v1/index.ts') diff --git a/packages/server/src/api/v1/index.ts b/packages/server/src/api/v1/index.ts index 31ab24f..00652a8 100644 --- a/packages/server/src/api/v1/index.ts +++ b/packages/server/src/api/v1/index.ts @@ -1,9 +1,10 @@ import { FastifyInstance, FastifyPluginOptions } from "fastify"; -import { verifyRepoName } from "../util"; import { GitAPI } from "../git"; +import { Route } from "../../fastify_types"; import repo from "./repo"; +import { verifyRepoName } from "../util"; -export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, done: any) { +export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, done: (err?: Error) => void): void { const git = new GitAPI(opts.config.settings.base_dir); fastify.setErrorHandler((err, req, reply) => { @@ -12,7 +13,7 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do }); fastify.setNotFoundHandler((req, reply) => { reply.code(404).send({ error: "Endpoint not found!" }); - }) + }); fastify.route({ method: "GET", @@ -31,23 +32,22 @@ export default function(fastify: FastifyInstance, opts: FastifyPluginOptions, do } }); - fastify.route({ + fastify.route({ method: "GET", url: "/repos/:repo", handler: async(req, reply) => { - const params: any = req.params; - const repo_verification = await verifyRepoName(opts.config.settings.base_dir, params.repo); + const repo_verification = await verifyRepoName(opts.config.settings.base_dir, req.params.repo); if(repo_verification.success === false && repo_verification.code) { reply.code(repo_verification.code).send({ error: repo_verification.message }); } - const desc = await git.getRepositoryFile(params.repo, "description"); + const desc = await git.getRepositoryFile(req.params.repo, "description"); - reply.send({ data: { name: params.repo, description: desc, has_readme: await git.doesReadmeExist(params.repo) } }); + reply.send({ data: { name: req.params.repo, description: desc, has_readme: await git.doesReadmeExist(req.params.repo) } }); } }); fastify.register(repo, { prefix: "/repos/:repo", config: { git: git, settings: opts.config.settings } }); done(); -}; \ No newline at end of file +} \ No newline at end of file -- cgit v1.2.3-18-g5258