diff --git a/pages/repo.go b/pages/repo.go index e59f5f5..66f7ac1 100644 --- a/pages/repo.go +++ b/pages/repo.go @@ -26,6 +26,7 @@ type Repo struct { Readme string Link string Tags []string + Branch []string } type RepoFiles struct { @@ -39,8 +40,11 @@ type RepoFiles struct { func HandleRepo(c *fiber.Ctx) error { var repoArray []Repo var repoFilesArray []RepoFiles - - resp, statusErr := http.Get("https://github.com/" + c.Params("user") + "/" + c.Params("repo")) + branchExists := "" + if strings.Count(c.Params("branch"), "")-1 > 0 { + branchExists = "/tree/" + c.Params("branch") + } + resp, statusErr := http.Get("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + branchExists) if statusErr != nil { log.Println(statusErr) } @@ -48,7 +52,7 @@ func HandleRepo(c *fiber.Ctx) error { // I need a better way to do this return c.Status(404).Render("error", fiber.Map{ "title": "Error", - "error": "Repository " + c.Params("user") + "/" + c.Params("repo") + " not found", + "error": "Repository " + c.Params("user") + "/" + c.Params("repo") + branchExists + " not found", }) } @@ -105,7 +109,7 @@ func HandleRepo(c *fiber.Ctx) error { }) }) - sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/") + sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + branchExists) // Add scrape-based info to repoArray repoArray = append(repoArray, Scrape) @@ -124,7 +128,7 @@ func HandleRepo(c *fiber.Ctx) error { readmeOutput := utils.UGCPolicy().SanitizeBytes(mightBeUnsafe) return c.Render("repo", fiber.Map{ - "title": "Repository " + c.Params("user") + "/" + c.Params("repo"), + "title": "Repository " + c.Params("user") + "/" + c.Params("repo") + branchExists, "repo": repoArray, "files": repoFilesArray, "readme": string(readmeOutput), diff --git a/serve/serve.go b/serve/serve.go index d2553d6..cd5be1c 100644 --- a/serve/serve.go +++ b/serve/serve.go @@ -108,6 +108,7 @@ func Serve() { app.Get("/:user/:repo", pages.HandleRepo) app.Get("/:user/:repo/blob/:branch/+", pages.FileView) app.Get("/:user/:repo/tree/:branch/+", pages.DirView) + app.Get("/:user/:repo/tree/:branch", pages.HandleRepo) app.Get("/download/:user/:repo/:branch", func(c *fiber.Ctx) error { utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/archive/"+c.Params("branch")+".zip") return nil diff --git a/views/dir.html b/views/dir.html index 8c9c2fd..559828d 100644 --- a/views/dir.html +++ b/views/dir.html @@ -6,7 +6,9 @@ View on GitHub - Back to {{.Fullname}} + Back to {{.Fullname}}
diff --git a/views/file.html b/views/file.html index 25bad9e..2a283b1 100644 --- a/views/file.html +++ b/views/file.html @@ -11,7 +11,9 @@ }
- Back to {{.fullname}} + Back to {{.fullname}}