add asset list support

This commit is contained in:
Arya Kiran
2023-05-16 16:46:20 +08:00
parent b308955ccf
commit 8dd74defb6
2 changed files with 19 additions and 5 deletions
+15 -5
View File
@@ -25,10 +25,9 @@ type Release struct {
Reactions []Reactions
}
type Assets struct {
Name string
Link string
Size string
ReleasedOn string
Name string
Link string
Size string
}
type Reactions struct {
Name string
@@ -93,9 +92,20 @@ func ReleaseView(c *fiber.Ctx) error {
Count: el.ChildText("span.js-discussion-reaction-group-count"),
})
})
})
sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/releases/" + c.Params("release"))
// Scrape assets from the fragment page
sc2 := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(UserAgent))
sc2.OnHTML("ul", func(e *colly.HTMLElement) {
e.ForEach("li", func(i int, el *colly.HTMLElement) {
Scrape.Assets = append(Scrape.Assets, Assets{
Name: el.ChildText("div.col-lg-9 a span"),
Link: el.ChildAttr("div.col-lg-9 a", "href"),
Size: el.ChildText("div.pl-1 span.text-sm-left"),
})
})
})
sc2.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/releases/expanded_assets/" + c.Params("release"))
// Add scrape-based info to releaseArray
releaseArray = append(releaseArray, Scrape)
+4
View File
@@ -115,6 +115,10 @@ func Serve(port string) {
app.Get("/:user/:repo/tree/:branch/+", pages.DirView)
app.Get("/:user/:repo/releases/:release", pages.ReleaseView)
app.Get("/:user/:repo/releases/tag/:release", pages.ReleaseView)
app.Get("/:user/:repo/releases/download/:release/:item", func(c *fiber.Ctx) error {
utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/releases/download"+c.Params("release")/c.Params("item"))
return nil
})
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")