diff --git a/main.go b/main.go
index 78642b9..21beb29 100644
--- a/main.go
+++ b/main.go
@@ -93,6 +93,7 @@ func main() {
app.Static("/logo.svg", "./public/assets/logo.svg")
app.Get("/explore", ratelimiter, pages.HandleExplore)
app.Get("/:user", ratelimiter, pages.HandleUser)
+ app.Get("/:user/:repo", ratelimiter, pages.HandleRepo)
app.Get("/avatar/:id", func(c *fiber.Ctx) error {
url := "https://avatars.githubusercontent.com/u/" + c.Params("id") + "?v=4"
if err := proxy.Do(c, url); err != nil {
@@ -102,5 +103,14 @@ func main() {
c.Response().Header.Del(fiber.HeaderServer)
return nil
})
+ app.Get("/download/:user/:repo/:branch", ratelimiter, func(c *fiber.Ctx) error {
+ url := "https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/archive/" + c.Params("branch") + ".zip"
+ if err := proxy.Do(c, url); err != nil {
+ return err
+ }
+ // Remove Server header from response
+ c.Response().Header.Del(fiber.HeaderServer)
+ return nil
+ })
log.Fatal(app.Listen(":3000"))
}
diff --git a/pages/explore.go b/pages/explore.go
index 19d7e5c..88b9886 100644
--- a/pages/explore.go
+++ b/pages/explore.go
@@ -20,7 +20,7 @@ type Items struct {
func HandleExplore(c *fiber.Ctx) error {
// get trending repos
trendingRepos := utils.GetRequest("https://api.github.com/search/repositories?q=code&sort=stars&order=desc&per_page=25")
- bruh2 := trendingRepos.Get("items").Array() // gjson.Result when I ask for an array. idiots, anyway so I have to do jank shit like this and I hate it. at least it works and is fast enough
+ bruh2 := trendingRepos.Get("tree").Array() // gjson.Result when I ask for an array. idiots, anyway so I have to do jank shit like this and I hate it. at least it works and is fast enough
var trendingReposArray []Items
for _, item := range bruh2 {
trendingReposArray = append(trendingReposArray, Items{
diff --git a/pages/repo.go b/pages/repo.go
new file mode 100644
index 0000000..0f8aac1
--- /dev/null
+++ b/pages/repo.go
@@ -0,0 +1,49 @@
+package pages
+
+import (
+ "codeberg.org/Odyssium/gothub/utils"
+ "github.com/gofiber/fiber/v2"
+)
+
+type Repo struct {
+ Fullname string
+ Description string
+ HtmlUrl string
+ Fork bool
+ Parent string
+ Stars int64
+ Forks int64
+ Watchers int64
+ Language string
+ License string
+ DefaultBranch string
+}
+
+type RepoFiles struct {
+ Name string
+ Path string
+ Type string
+}
+
+func HandleRepo(c *fiber.Ctx) error {
+ var repoArray []Repo
+ // get repo
+ repo := utils.GetRequest("https://api.github.com/repos/" + c.Params("user") + "/" + c.Params("repo"))
+ repoArray = append(repoArray, Repo{
+ Fullname: repo.Get("full_name").String(),
+ Description: repo.Get("description").String(),
+ HtmlUrl: repo.Get("html_url").String(),
+ Fork: repo.Get("fork").Bool(),
+ Stars: repo.Get("stargazers_count").Int(),
+ Forks: repo.Get("forks_count").Int(),
+ Watchers: repo.Get("watchers_count").Int(),
+ Language: repo.Get("language").String(),
+ License: repo.Get("license").Get("name").String(),
+ Parent: repo.Get("parent").Get("full_name").String(),
+ DefaultBranch: repo.Get("default_branch").String(),
+ })
+
+ return c.Render("repo", fiber.Map{
+ "repo": repoArray,
+ })
+}
diff --git a/public/css/global.css b/public/css/global.css
index 8dc317f..7aa4805 100644
--- a/public/css/global.css
+++ b/public/css/global.css
@@ -150,6 +150,30 @@ a:hover {
margin-top: 0;
}
+/* URI: /:user/:repo */
+.downloadButton {
+ background-color: var(--background);
+ padding: 8px;
+ border-radius: 8px;
+ margin: 8px;
+ color: var(--text);
+ text-decoration: none;
+ text-align: center;
+ display: inline-block;
+}
+
+.downloadButton:hover {
+ background-color: var(--accent);
+ color: var(--text);
+}
+
+.buttonParent {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+}
+
@media screen and (prefers-color-scheme: light) {
:root {
--text: #000;
diff --git a/views/explore.html b/views/explore.html
index 670ac6a..aaec28d 100644
--- a/views/explore.html
+++ b/views/explore.html
@@ -6,7 +6,7 @@
{{ if .repos}}
{{ range $key, $value := .repos}}
-
{{ .Fullname }}
+
{{ .Fullname }}
{{.Description}}
{{ if .Language }}
{{ if .License }}
diff --git a/views/repo.html b/views/repo.html
new file mode 100644
index 0000000..fbf011f
--- /dev/null
+++ b/views/repo.html
@@ -0,0 +1,44 @@
+{{ template "header" .}}
+
+
+ {{ if .repo }}
+ {{ range $key, $value := .repo}}
+
+
+
+
{{.Fullname}}
+ {{ if .Fork }}
+
This repository is a fork of {{.Parent}}.
+ {{ end }}
+ {{ if .Description }}
+
{{.Description}}
+ {{ end }}
+ {{ if .Language}}
+ {{ if .License }}
+
⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ {{.License}} 🗒️ {{.Language}}
+ {{ else }}
+
⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license 🗒️ {{.Language}}
+ {{ end }}
+ {{ else }}
+ {{ end }}
+
+ {{end}}
+
+ {{ else }}
+ Repository not found
+ That repository doesn't exist.
+ {{ end }}
+
\ No newline at end of file