From 940c186cd8dd1d2bd12fa9405400f717fe32440e Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Sun, 25 Jan 2026 16:27:48 -0500 Subject: Refactor --- cgithub/src/index.ts | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'cgithub/src/index.ts') diff --git a/cgithub/src/index.ts b/cgithub/src/index.ts index 525ac74..fcd0069 100644 --- a/cgithub/src/index.ts +++ b/cgithub/src/index.ts @@ -14,45 +14,15 @@ const eta = new Eta({ views: path.join(__dirname, "..", "views") }); app.use("/static/*", serveStatic({ root: path.join(__dirname, "..") })); app.get("/:owner/:repo/tree/:branch/:path{.*}?", async (c) => { - try { - const owner = c.req.param("owner"); - const repo = c.req.param("repo"); - const branch = c.req.param("branch"); - const path = c.req.param("path") || ""; - - const data = await getGitHubTree(owner, repo, branch, path); - const html = await eta.renderAsync("tree.eta", data); - - return c.html(html); - } catch (error) { - const errorMessage = - error instanceof Error ? error.message : "Unknown error"; - return c.html( - `

Error

${errorMessage}

`, - 500, - ); - } + const { owner, repo, branch, path = "" } = c.req.param(); + const data = await getGitHubTree(owner, repo, branch, path); + return c.html(await eta.renderAsync("tree.eta", data)); }); app.get("/:owner/:repo/blob/:branch/:path{.*}", async (c) => { - try { - const owner = c.req.param("owner"); - const repo = c.req.param("repo"); - const branch = c.req.param("branch"); - const path = c.req.param("path"); - - const data = await getGitHubBlob(owner, repo, branch, path); - const html = await eta.renderAsync("blob.eta", data); - - return c.html(html); - } catch (error) { - const errorMessage = - error instanceof Error ? error.message : "Unknown error"; - return c.html( - `

Error

${errorMessage}

`, - 500, - ); - } + const { owner, repo, branch, path } = c.req.param(); + const data = await getGitHubBlob(owner, repo, branch, path); + return c.html(await eta.renderAsync("blob.eta", data)); }); if (process.env.LISTEN_FDS === "1") { -- cgit v1.3.1