replace *?type=gist with /gist/*

このコミットが含まれているのは:
medanisjbara 2023-04-01 11:17:08 +01:00
コミット bb7167c3c8
3個のファイルの変更17行の追加25行の削除

ファイルの表示

@ -38,7 +38,7 @@ func HandleGist(c *fiber.Ctx) error {
var gistArray []Gist
var gistFilesArray []GistFiles
resp, statusErr := http.Get("https://gists.github.com/" + c.Params("user") + "/" + c.Params("repo"))
resp, statusErr := http.Get("https://gists.github.com/" + c.Params("user") + "/" + c.Params("gistID"))
if statusErr != nil {
log.Println(statusErr)
}
@ -46,7 +46,7 @@ func HandleGist(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": "Gist repository " + c.Params("user") + "/" + c.Params("gistID") + " not found",
})
}
@ -61,17 +61,16 @@ func HandleGist(c *fiber.Ctx) error {
sc := colly.NewCollector(colly.AllowedDomains("gist.github.com"), colly.UserAgent(UserAgent))
sc.OnHTML("div.gisthead", func(e *colly.HTMLElement) {
Scrape.Refname = c.Params("user") + "/" + c.Params("repo")
Scrape.Fullname = c.Params("user") + "/" + e.ChildText("a[href='/"+c.Params("user")+"/"+c.Params("repo")+"' i]")
Scrape.Refname = c.Params("user") + "/" + c.Params("gistID")
Scrape.Fullname = c.Params("user") + "/" + e.ChildText("a[href='/"+c.Params("user")+"/"+c.Params("gistID")+"' i]")
dl := e.ChildAttr("a[href$='.zip']", "href")
Scrape.Revision = dl[strings.LastIndex(dl,"/")+1 : len(dl)-len(".zip")]
Scrape.Stars = e.ChildText("ul li a:first")
Scrape.Stars = e.ChildText("li a[href*='/" + c.Params("user") + "/" + c.Params("repo") + "/stargazers' i]")
Scrape.Stars = e.ChildText("li a[href*='/" + c.Params("user") + "/" + c.Params("gistID") + "/stargazers' i]")
Scrape.Parent = e.ChildText("span.note a")
Scrape.Forks = e.ChildText("li span.social-count")
// I need a better way to do this
if Scrape.Forks == "" {
Scrape.Forks = e.ChildText("li a[href*='/" + c.Params("user") + "/" + c.Params("repo") + "/forks' i]")
Scrape.Forks = e.ChildText("li a[href*='/" + c.Params("user") + "/" + c.Params("gistID") + "/forks' i]")
}
})
@ -127,12 +126,12 @@ func HandleGist(c *fiber.Ctx) error {
})
})
sc.Visit("https://gist.github.com/" + c.Params("user") + "/" + c.Params("repo") + "/")
sc.Visit("https://gist.github.com/" + c.Params("user") + "/" + c.Params("gistID") + "/")
// Add scrape-based info to gistArray
gistArray = append(gistArray, Scrape)
return c.Render("gist", fiber.Map{
"title": "Repository " + c.Params("user") + "/" + c.Params("repo"),
"title": "Repository " + c.Params("user") + "/" + c.Params("gistID"),
"gist": gistArray,
"files": gistFilesArray,
})

ファイルの表示

@ -108,27 +108,20 @@ func Serve(port string) {
utils.ProxyRequest(c, "https://avatars.githubusercontent.com/u/"+c.Params("id")+"?v=4")
return nil
})
app.Get("/:user/:repo", func(c *fiber.Ctx) error {
if c.Query("type") == "gist" {
return pages.HandleGist(c)
}
return pages.HandleRepo(c)
})
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 {
var baseURL string
if c.Query("type") == "gist" {
baseURL = "https://gist.github.com/"
} else {
baseURL = "https://github.com/"
}
url := baseURL + c.Params("user") + "/" + c.Params("repo") + "/archive/" + c.Params("branch") + ".zip"
utils.ProxyRequest(c, url)
utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+"/archive/"+c.Params("branch")+".zip")
return nil
})
app.Get("/gist/:user/:gistID", pages.HandleGist)
app.Get("/download/gist/:user/:gistID/:revision", func(c *fiber.Ctx) error {
utils.ProxyRequest(c, "https://gist.github.com/"+c.Params("user")+"/"+c.Params("gistID")+"/archive/"+c.Params("revision")+".zip")
return nil
})
app.Get("/raw/:user/:repo/:branch/:file", func(c *fiber.Ctx) error {
utils.ProxyRequest(c, "https://raw.githubusercontent.com/"+c.Params("user")+"/"+c.Params("repo")+"/"+c.Params("branch")+"/"+c.Params("file"))
return nil

ファイルの表示

@ -3,7 +3,7 @@
<main>
{{ if .gist }} {{ range $key, $value := .gist}}
<div class="buttonParent">
<a href="/download/{{.Refname}}/{{.Revision}}?type=gist" class="button"
<a href="/download/gist/{{.Refname}}/{{$value.Revision}}" class="button"
>Download (zip)</a
>
<a href="https://gist.github.com/{{.Refname}}" class="button"