fixed homepage not respecting homepage.show field, disabled schema validation for included file

This commit is contained in:
yusing 2024-10-04 08:36:32 +08:00
parent 6211ddcdf0
commit e566fd9b57
6 changed files with 33 additions and 15 deletions

View file

@ -12,7 +12,7 @@ import (
) )
var ( 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") IsTest = GetEnvBool("GOPROXY_TEST", false) || strings.HasSuffix(os.Args[0], ".test")
IsDebug = GetEnvBool("GOPROXY_DEBUG", IsTest) IsDebug = GetEnvBool("GOPROXY_DEBUG", IsTest)

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/sirupsen/logrus"
"github.com/yusing/go-proxy/internal/common" "github.com/yusing/go-proxy/internal/common"
H "github.com/yusing/go-proxy/internal/homepage" H "github.com/yusing/go-proxy/internal/homepage"
M "github.com/yusing/go-proxy/internal/models" M "github.com/yusing/go-proxy/internal/models"
@ -48,10 +49,18 @@ func (cfg *Config) HomepageConfig() H.HomePageConfig {
} }
entry := r.Entry() 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 item := entry.Homepage
if !item.Initialized { if !item.Show && !item.IsEmpty() {
item.Show = r.Entry().IsExplicit || !p.IsExplicitOnly() item.Show = true
} }
if !item.Show || r.Type() != R.RouteTypeReverseProxy { if !item.Show || r.Type() != R.RouteTypeReverseProxy {
@ -86,7 +95,7 @@ func (cfg *Config) HomepageConfig() H.HomePageConfig {
} }
item.AltURL = r.URL().String() item.AltURL = r.URL().String()
hpCfg.Add(&item) hpCfg.Add(item)
}) })
return hpCfg return hpCfg
} }

View file

@ -58,7 +58,14 @@ func ApplyLabel[T any](obj *T, l *Label) E.NestedError {
} }
dst, ok := field.Interface().(NestedLabelMap) dst, ok := field.Interface().(NestedLabelMap)
if !ok { 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 { if dst == nil {
field.Set(reflect.MakeMap(reflect.TypeFor[NestedLabelMap]())) field.Set(reflect.MakeMap(reflect.TypeFor[NestedLabelMap]()))

View file

@ -13,12 +13,20 @@ type (
Description string `yaml:"description" json:"description"` Description string `yaml:"description" json:"description"`
WidgetConfig map[string]any `yaml:",flow" json:"widget_config"` WidgetConfig map[string]any `yaml:",flow" json:"widget_config"`
SourceType string `yaml:"-" json:"source_type"` SourceType string `yaml:"-" json:"source_type"`
Initialized bool `yaml:"-" json:"-"` AltURL string `yaml:"-" json:"alt_url"` // original proxy target
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 { func NewHomePageConfig() HomePageConfig {
return HomePageConfig(make(map[string]HomePageCategory)) return HomePageConfig(make(map[string]HomePageCategory))
} }

View file

@ -22,7 +22,7 @@ type (
NoTLSVerify bool `yaml:"no_tls_verify" json:"no_tls_verify,omitempty"` // https proxy only 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 PathPatterns []string `yaml:"path_patterns" json:"path_patterns,omitempty"` // http(s) proxy only
Middlewares D.NestedLabelMap `yaml:"middlewares" json:"middlewares,omitempty"` Middlewares D.NestedLabelMap `yaml:"middlewares" json:"middlewares,omitempty"`
Homepage H.HomePageItem `yaml:"homepage" json:"homepage"` Homepage *H.HomePageItem `yaml:"homepage" json:"homepage"`
/* Docker only */ /* Docker only */
*D.ProxyProperties `yaml:"-" json:"proxy_properties"` *D.ProxyProperties `yaml:"-" json:"proxy_properties"`

View file

@ -79,12 +79,6 @@ func (p *FileProvider) LoadRoutesImpl() (routes R.Routes, res E.NestedError) {
return return
} }
if !common.NoSchemaValidation {
if err = Validate(data); err.HasError() {
b.Add(err)
return
}
}
if err = entries.UnmarshalFromYAML(data); err.HasError() { if err = entries.UnmarshalFromYAML(data); err.HasError() {
b.Add(err) b.Add(err)
return return