From e566fd9b57b2e20a4476c2bd80285d7458613730 Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 4 Oct 2024 08:36:32 +0800 Subject: [PATCH] fixed homepage not respecting homepage.show field, disabled schema validation for included file --- internal/common/env.go | 2 +- internal/config/query.go | 15 ++++++++++++--- internal/docker/label.go | 9 ++++++++- internal/homepage/homepage.go | 14 +++++++++++--- internal/models/raw_entry.go | 2 +- internal/proxy/provider/file.go | 6 ------ 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/internal/common/env.go b/internal/common/env.go index 5c5c3baa..038da1dc 100644 --- a/internal/common/env.go +++ b/internal/common/env.go @@ -12,7 +12,7 @@ import ( ) var ( - NoSchemaValidation = GetEnvBool("GOPROXY_NO_SCHEMA_VALIDATION", false) + NoSchemaValidation = GetEnvBool("GOPROXY_NO_SCHEMA_VALIDATION", true) IsTest = GetEnvBool("GOPROXY_TEST", false) || strings.HasSuffix(os.Args[0], ".test") IsDebug = GetEnvBool("GOPROXY_DEBUG", IsTest) diff --git a/internal/config/query.go b/internal/config/query.go index ebb1f2d1..6ecbaeaa 100644 --- a/internal/config/query.go +++ b/internal/config/query.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/sirupsen/logrus" "github.com/yusing/go-proxy/internal/common" H "github.com/yusing/go-proxy/internal/homepage" M "github.com/yusing/go-proxy/internal/models" @@ -48,10 +49,18 @@ func (cfg *Config) HomepageConfig() H.HomePageConfig { } entry := r.Entry() + if entry.Homepage == nil { + entry.Homepage = &H.HomePageItem{ + Show: r.Entry().IsExplicit || !p.IsExplicitOnly(), + } + } + + logrus.Debugf("%s isexplicit: %v, explicitonly: %v", r, r.Entry().IsExplicit, p.IsExplicitOnly()) + item := entry.Homepage - if !item.Initialized { - item.Show = r.Entry().IsExplicit || !p.IsExplicitOnly() + if !item.Show && !item.IsEmpty() { + item.Show = true } if !item.Show || r.Type() != R.RouteTypeReverseProxy { @@ -86,7 +95,7 @@ func (cfg *Config) HomepageConfig() H.HomePageConfig { } item.AltURL = r.URL().String() - hpCfg.Add(&item) + hpCfg.Add(item) }) return hpCfg } diff --git a/internal/docker/label.go b/internal/docker/label.go index aa119090..bea124ad 100644 --- a/internal/docker/label.go +++ b/internal/docker/label.go @@ -58,7 +58,14 @@ func ApplyLabel[T any](obj *T, l *Label) E.NestedError { } dst, ok := field.Interface().(NestedLabelMap) if !ok { - return U.Deserialize(U.SerializedObject{nestedLabel.Namespace: nestedLabel.Value}, field.Addr().Interface()) + if field.Kind() == reflect.Ptr { + if field.IsNil() { + field.Set(reflect.New(field.Type().Elem())) + } + } else { + field = field.Addr() + } + return U.Deserialize(U.SerializedObject{nestedLabel.Namespace: nestedLabel.Value}, field.Interface()) } if dst == nil { field.Set(reflect.MakeMap(reflect.TypeFor[NestedLabelMap]())) diff --git a/internal/homepage/homepage.go b/internal/homepage/homepage.go index 5ef178f4..1c9a7b5d 100644 --- a/internal/homepage/homepage.go +++ b/internal/homepage/homepage.go @@ -13,12 +13,20 @@ type ( Description string `yaml:"description" json:"description"` WidgetConfig map[string]any `yaml:",flow" json:"widget_config"` - SourceType string `yaml:"-" json:"source_type"` - Initialized bool `yaml:"-" json:"-"` - AltURL string `yaml:"-" json:"alt_url"` // original proxy target + SourceType string `yaml:"-" json:"source_type"` + AltURL string `yaml:"-" json:"alt_url"` // original proxy target } ) +func (item *HomePageItem) IsEmpty() bool { + return item == nil || (item.Name == "" && + item.Icon == "" && + item.URL == "" && + item.Category == "" && + item.Description == "" && + len(item.WidgetConfig) == 0) +} + func NewHomePageConfig() HomePageConfig { return HomePageConfig(make(map[string]HomePageCategory)) } diff --git a/internal/models/raw_entry.go b/internal/models/raw_entry.go index d6c0d191..bc280c85 100644 --- a/internal/models/raw_entry.go +++ b/internal/models/raw_entry.go @@ -22,7 +22,7 @@ type ( NoTLSVerify bool `yaml:"no_tls_verify" json:"no_tls_verify,omitempty"` // https proxy only PathPatterns []string `yaml:"path_patterns" json:"path_patterns,omitempty"` // http(s) proxy only Middlewares D.NestedLabelMap `yaml:"middlewares" json:"middlewares,omitempty"` - Homepage H.HomePageItem `yaml:"homepage" json:"homepage"` + Homepage *H.HomePageItem `yaml:"homepage" json:"homepage"` /* Docker only */ *D.ProxyProperties `yaml:"-" json:"proxy_properties"` diff --git a/internal/proxy/provider/file.go b/internal/proxy/provider/file.go index a227fa71..e827f500 100644 --- a/internal/proxy/provider/file.go +++ b/internal/proxy/provider/file.go @@ -79,12 +79,6 @@ func (p *FileProvider) LoadRoutesImpl() (routes R.Routes, res E.NestedError) { return } - if !common.NoSchemaValidation { - if err = Validate(data); err.HasError() { - b.Add(err) - return - } - } if err = entries.UnmarshalFromYAML(data); err.HasError() { b.Add(err) return