Reverse proxy gist downloads
このコミットが含まれているのは:
コミット
3f45c5ca7c
@ -22,7 +22,7 @@ type Gist struct {
|
||||
Fullname string
|
||||
Refname string
|
||||
Description string
|
||||
DownloadLink string
|
||||
Revision string
|
||||
Parent string
|
||||
Stars string
|
||||
Forks string
|
||||
@ -63,7 +63,8 @@ func HandleGist(c *fiber.Ctx) error {
|
||||
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.DownloadLink = e.ChildAttr("a[href$='.zip']", "href")
|
||||
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.Parent = e.ChildText("span.note a")
|
||||
|
@ -118,7 +118,15 @@ func Serve(port string) {
|
||||
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")
|
||||
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)
|
||||
return nil
|
||||
})
|
||||
app.Get("/raw/:user/:repo/:branch/:file", func(c *fiber.Ctx) error {
|
||||
|
@ -3,7 +3,7 @@
|
||||
<main>
|
||||
{{ if .gist }} {{ range $key, $value := .gist}}
|
||||
<div class="buttonParent">
|
||||
<a href="https://gist.github.com/{{.DownloadLink}}" class="button"
|
||||
<a href="/download/{{.Refname}}/{{.Revision}}?type=gist" class="button"
|
||||
>Download (zip)</a
|
||||
>
|
||||
<a href="https://gist.github.com/{{.Refname}}" class="button"
|
||||
|
読み込み中…
新しいイシューから参照
ユーザーをブロックする