From 97b9a6c831aab58be985cc1e9cd16e0f32b71f5b Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Sun, 25 Jan 2026 16:27:48 -0500 Subject: Refactor --- src/index.ts | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 525ac74..fcd0069 100644 --- a/src/index.ts +++ b/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