diff --git a/pages/dirview.go b/pages/dirview.go index 287de13..b49a334 100644 --- a/pages/dirview.go +++ b/pages/dirview.go @@ -1,12 +1,12 @@ package pages import ( + "fmt" + "github.com/tidwall/gjson" "log" "net/http" "os" - "fmt" - "github.com/tidwall/gjson" - + "codeberg.org/gothub/gothub/utils" "github.com/gocolly/colly" "github.com/gofiber/fiber/v2" @@ -56,34 +56,31 @@ func DirView(c *fiber.Ctx) error { } sc := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(UserAgent)) - + sc.OnResponse(func(r *colly.Response) { jsonMess := string(r.Body) dirList := gjson.Get(jsonMess, "payload.tree.items") - + dirList.ForEach(func(i, e gjson.Result) bool { var FileType string - if(e.Get("contentType").Str == "directory"){ + if e.Get("contentType").Str == "directory" { FileType = "dir" } else { FileType = "file" } - + dirFilesArray = append(dirFilesArray, DirFiles{ Name: e.Get("name").Str, // Path is the path to the file/folder from the repository root - Path: e.Get("path").Str, - Type: FileType, - Branch: Scrape.Branch, + Path: e.Get("path").Str, + Type: FileType, + Branch: Scrape.Branch, Fullname: Scrape.Fullname, }) - - fmt.Println(dirFilesArray) - + return true //keep iterating }) - fmt.Println(dirList) - + }) sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/tree/" + c.Params("branch") + "/" + c.Params("+"))