add support for cloning git repos via gothub :D

このコミットが含まれているのは:
Arya Kiran 2023-06-03 00:58:33 +08:00
コミット d96074580e
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 842D12BDA50DF120
1個のファイルの変更23行の追加2行の削除

ファイルの表示

@ -15,6 +15,8 @@ import (
"github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/limiter"
// For debugging purposes
// "github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/template/html"
@ -62,6 +64,10 @@ func Serve(port string) {
app.Use(cache.New(cache.Config{
Expiration: 5 * time.Minute,
}))
// For debugging purposes
// app.Use(logger.New(logger.Config{
// Format: "[${ip}]:${port} ${status} - ${method} ${path} ${queryParams}\n",
// }))
app.Use(compress.New(compress.Config{
Level: compress.LevelBestSpeed, // 1
@ -124,6 +130,21 @@ func Serve(port string) {
}
})
app.Get("/:user/:repo", pages.HandleRepo)
app.Get("/:user/:repo/info/+", func(c *fiber.Ctx) error {
// This is needed but it looks like git doesn't send it. Or maybe i just shouldn't program at midnight
param := "?service=git-upload-pack"
if proxying == "true" {
utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+".git/info/"+c.Params("+")+param)
return nil
} else {
c.Redirect("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + ".git/info/" + c.Params("+") + param)
return nil
}
})
app.Post("/:user/:repo/git-upload-pack", func(c *fiber.Ctx) error {
utils.ProxyRequest(c, "https://github.com/"+c.Params("user")+"/"+c.Params("repo")+".git/git-upload-pack")
return nil
})
app.Get("/:user/:repo/blob/:branch/+", pages.FileView)
app.Get("/:user/:repo/tree/:branch/+", pages.DirView)
app.Get("/:user/:repo/tree/:branch", pages.HandleRepo)
@ -150,7 +171,7 @@ func Serve(port string) {
utils.ProxyRequest(c, "https://camo.githubusercontent.com/"+c.Params("p1")+"/"+c.Params("p2"))
return nil
} else {
c.Redirect("https://camo.githubusercontent.com/"+c.Params("p1")+"/"+c.Params("p2"))
c.Redirect("https://camo.githubusercontent.com/" + c.Params("p1") + "/" + c.Params("p2"))
return nil
}
})
@ -160,7 +181,7 @@ func Serve(port string) {
utils.ProxyRequest(c, "https://gist.github.com/"+c.Params("user")+"/"+c.Params("gistID")+"/archive/"+c.Params("revision")+".zip")
return nil
} else {
c.Redirect("https://gist.github.com/"+c.Params("user")+"/"+c.Params("gistID")+"/archive/"+c.Params("revision")+".zip")
c.Redirect("https://gist.github.com/" + c.Params("user") + "/" + c.Params("gistID") + "/archive/" + c.Params("revision") + ".zip")
return nil
}
})