diff options
| author | Joe Mou <dev@mou.fo> | 2026-01-25 16:27:48 -0500 |
|---|---|---|
| committer | Joe Mou <dev@mou.fo> | 2026-01-25 17:46:15 -0500 |
| commit | 940c186cd8dd1d2bd12fa9405400f717fe32440e (patch) | |
| tree | 9546777fb3765a5b971468aa6cf345448142747e /cgithub/src/index.ts | |
| parent | 0d7a3f22edabf680b098fc89337fd7f21088fbdd (diff) | |
Refactor
Diffstat (limited to 'cgithub/src/index.ts')
| -rw-r--r-- | cgithub/src/index.ts | 42 |
1 files changed, 6 insertions, 36 deletions
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( - `<html><body><h1>Error</h1><p>${errorMessage}</p></body></html>`, - 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( - `<html><body><h1>Error</h1><p>${errorMessage}</p></body></html>`, - 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") { |
