mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
improved homepage labels
This commit is contained in:
parent
90130411f9
commit
90bababd38
5 changed files with 52 additions and 19 deletions
2
go.mod
2
go.mod
|
@ -11,6 +11,7 @@ require (
|
|||
github.com/santhosh-tekuri/jsonschema v1.2.4
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
golang.org/x/net v0.29.0
|
||||
golang.org/x/text v0.18.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
|
@ -50,7 +51,6 @@ require (
|
|||
golang.org/x/oauth2 v0.23.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
golang.org/x/time v0.6.0 // indirect
|
||||
golang.org/x/tools v0.25.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/common"
|
||||
H "github.com/yusing/go-proxy/internal/homepage"
|
||||
M "github.com/yusing/go-proxy/internal/models"
|
||||
PR "github.com/yusing/go-proxy/internal/proxy/provider"
|
||||
|
@ -26,12 +30,51 @@ func (cfg *Config) DumpProviders() map[string]*PR.Provider {
|
|||
}
|
||||
|
||||
func (cfg *Config) HomepageConfig() H.HomePageConfig {
|
||||
var proto, port string
|
||||
domains := cfg.value.MatchDomains
|
||||
cert, _ := cfg.autocertProvider.GetCert(nil)
|
||||
if cert != nil {
|
||||
proto = "https"
|
||||
port = common.ProxyHTTPPort
|
||||
} else {
|
||||
proto = "http"
|
||||
port = common.ProxyHTTPSPort
|
||||
}
|
||||
|
||||
hpCfg := H.NewHomePageConfig()
|
||||
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) {
|
||||
if !r.Started() {
|
||||
return
|
||||
}
|
||||
hpCfg.Add(*r.Entry().Homepage)
|
||||
|
||||
entry := r.Entry()
|
||||
item := entry.Homepage
|
||||
if item == nil {
|
||||
item = &H.HomePageItem{}
|
||||
}
|
||||
|
||||
if item.Name == "" {
|
||||
item.Name = U.Title(alias)
|
||||
}
|
||||
|
||||
if p.GetType() == PR.ProviderTypeDocker {
|
||||
if item.Category == "" {
|
||||
item.Category = "Docker"
|
||||
}
|
||||
item.SourceType = string(PR.ProviderTypeDocker)
|
||||
} else if p.GetType() == PR.ProviderTypeFile {
|
||||
if item.Category == "" {
|
||||
item.Category = "Others"
|
||||
}
|
||||
item.SourceType = string(PR.ProviderTypeFile)
|
||||
}
|
||||
|
||||
if item.URL == "" && r.Type() == R.RouteTypeReverseProxy {
|
||||
if len(domains) > 0 {
|
||||
item.URL = fmt.Sprintf("%s://%s.%s:%s", proto, strings.ToLower(alias), domains[0], port)
|
||||
}
|
||||
}
|
||||
hpCfg.Add(item)
|
||||
})
|
||||
return hpCfg
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package homepage
|
|||
|
||||
type (
|
||||
HomePageConfig map[string]HomePageCategory
|
||||
HomePageCategory []HomePageItem
|
||||
HomePageCategory []*HomePageItem
|
||||
|
||||
HomePageItem struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Icon string `yaml:"icon" json:"icon,omitempty"` // URL or unicodes
|
||||
Icon string `yaml:"icon" json:"icon,omitempty"`
|
||||
URL string `yaml:"url" json:"url,omitempty"` // URL or unicodes
|
||||
Category string `yaml:"category" json:"category"`
|
||||
SourceType string `yaml:"source_type" json:"source_type,omitempty"`
|
||||
Description string `yaml:"description" json:"description,omitempty"`
|
||||
WidgetConfig map[string]any `yaml:",flow" json:"widget_config,omitempty"`
|
||||
}
|
||||
|
@ -17,19 +19,11 @@ func NewHomePageConfig() HomePageConfig {
|
|||
return HomePageConfig(make(map[string]HomePageCategory))
|
||||
}
|
||||
|
||||
func HomePageItemDefault() *HomePageItem {
|
||||
return &HomePageItem{
|
||||
Name: "Docker",
|
||||
Category: "Uncategorized",
|
||||
WidgetConfig: make(map[string]any),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *HomePageConfig) Clear() {
|
||||
*c = make(HomePageConfig)
|
||||
}
|
||||
|
||||
func (c HomePageConfig) Add(item HomePageItem) {
|
||||
func (c HomePageConfig) Add(item *HomePageItem) {
|
||||
if c[item.Category] == nil {
|
||||
c[item.Category] = make(HomePageCategory, 0)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
. "github.com/yusing/go-proxy/internal/common"
|
||||
D "github.com/yusing/go-proxy/internal/docker"
|
||||
H "github.com/yusing/go-proxy/internal/homepage"
|
||||
U "github.com/yusing/go-proxy/internal/utils"
|
||||
F "github.com/yusing/go-proxy/internal/utils/functional"
|
||||
)
|
||||
|
||||
|
@ -40,11 +39,6 @@ func (e *RawEntry) FillMissingFields() {
|
|||
e.ProxyProperties = &D.ProxyProperties{}
|
||||
}
|
||||
|
||||
if e.Homepage == nil {
|
||||
e.Homepage = H.HomePageItemDefault()
|
||||
e.Homepage.Name = U.Title(e.Alias)
|
||||
}
|
||||
|
||||
lp, pp, extra := e.splitPorts()
|
||||
|
||||
if port, ok := ServiceNamePortMapTCP[e.ImageName]; ok {
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
D "github.com/yusing/go-proxy/internal/docker"
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
H "github.com/yusing/go-proxy/internal/homepage"
|
||||
M "github.com/yusing/go-proxy/internal/models"
|
||||
R "github.com/yusing/go-proxy/internal/route"
|
||||
W "github.com/yusing/go-proxy/internal/watcher"
|
||||
|
@ -184,6 +185,7 @@ func (p *DockerProvider) entriesFromContainerLabels(container D.Container) (entr
|
|||
Alias: a,
|
||||
Host: p.hostname,
|
||||
ProxyProperties: container.ProxyProperties,
|
||||
Homepage: &H.HomePageItem{},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue