make it conf via arg or env

This commit is contained in:
6543 2022-07-24 17:52:07 +02:00
parent aa83b307db
commit b1b23ce2ec
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
5 changed files with 17 additions and 5 deletions

View file

@ -69,6 +69,17 @@ var ServeFlags = []cli.Flag{
// TODO: desc
EnvVars: []string{"ENABLE_HTTP_SERVER"},
},
// Server Options
&cli.BoolFlag{
Name: "enable-lfs-support",
Usage: "enable lfs support, require gitea v1.17.0 as backend",
EnvVars: []string{"ENABLE_LFS_SUPPORT"},
},
&cli.BoolFlag{
Name: "enable-symlink-support",
Usage: "follow symlinks if enabled, require gitea v1.18.0 as backend",
EnvVars: []string{"ENABLE_SYMLINK_SUPPORT"},
},
// ACME
&cli.StringFlag{

View file

@ -82,7 +82,7 @@ func Serve(ctx *cli.Context) error {
// TODO: make this an MRU cache with a size limit
fileResponseCache := cache.NewKeyValueCache()
giteaClient, err := gitea.NewClient(giteaRoot, giteaAPIToken)
giteaClient, err := gitea.NewClient(giteaRoot, giteaAPIToken, ctx.Bool("enable-symlink-support"), ctx.Bool("enable-lfs-support"))
if err != nil {
return fmt.Errorf("could not create new gitea client: %v", err)
}

View file

@ -9,6 +9,7 @@ import (
"io"
"net/http"
"net/http/cookiejar"
"strings"
"testing"
"github.com/rs/zerolog/log"

View file

@ -44,7 +44,7 @@ func joinURL(baseURL string, paths ...string) string {
return baseURL + "/" + strings.Join(p, "/")
}
func NewClient(giteaRoot, giteaAPIToken string) (*Client, error) {
func NewClient(giteaRoot, giteaAPIToken string, followSymlinks, supportLFS bool) (*Client, error) {
rootURL, err := url.Parse(giteaRoot)
giteaRoot = strings.Trim(rootURL.String(), "/")
@ -55,8 +55,8 @@ func NewClient(giteaRoot, giteaAPIToken string) (*Client, error) {
contentTimeout: 10 * time.Second,
fastClient: getFastHTTPClient(),
followSymlinks: true,
supportLFS: true,
followSymlinks: followSymlinks,
supportLFS: supportLFS,
}, err
}

View file

@ -13,7 +13,7 @@ import (
func TestHandlerPerformance(t *testing.T) {
giteaRoot := "https://codeberg.org"
giteaClient, _ := gitea.NewClient(giteaRoot, "")
giteaClient, _ := gitea.NewClient(giteaRoot, "", false, false)
testHandler := Handler(
[]byte("codeberg.page"), []byte("raw.codeberg.org"),
giteaClient,