aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/api/v1/index.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-06-22 13:31:43 +0200
committerHampusM <hampus@hampusmat.com>2021-06-22 13:31:43 +0200
commit43faf0bfd5544f9338e1442ab5b1fcb3210867ac (patch)
tree98ef97249f6a927b1cfba41b8a3587fd211a68e1 /packages/server/src/api/v1/index.ts
parente59d40c2b662a570f679c133a7fe26d1b47edd89 (diff)
Refactored the backend yet again & got eslint too work with typescript
Diffstat (limited to 'packages/server/src/api/v1/index.ts')
-rw-r--r--packages/server/src/api/v1/index.ts18
1 files changed, 9 insertions, 9 deletions
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<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