api: homepage config json not longer include default url

This commit is contained in:
yusing 2025-01-04 03:37:51 +08:00
parent cb9b7d55fd
commit 6b669fc540
2 changed files with 4 additions and 20 deletions

View file

@ -1,10 +1,8 @@
package config package config
import ( import (
"fmt"
"strings" "strings"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/homepage" "github.com/yusing/go-proxy/internal/homepage"
route "github.com/yusing/go-proxy/internal/route" route "github.com/yusing/go-proxy/internal/route"
"github.com/yusing/go-proxy/internal/route/entry" "github.com/yusing/go-proxy/internal/route/entry"
@ -33,17 +31,6 @@ func DumpProviders() map[string]*proxy.Provider {
} }
func HomepageConfig() homepage.Config { func HomepageConfig() homepage.Config {
var proto, port string
domains := instance.value.MatchDomains
cert, _ := instance.autocertProvider.GetCert(nil)
if cert != nil {
proto = "https"
port = common.ProxyHTTPSPort
} else {
proto = "http"
port = common.ProxyHTTPPort
}
hpCfg := homepage.NewHomePageConfig() hpCfg := homepage.NewHomePageConfig()
routes.GetHTTPRoutes().RangeAll(func(alias string, r types.HTTPRoute) { routes.GetHTTPRoutes().RangeAll(func(alias string, r types.HTTPRoute) {
en := r.RawEntry() en := r.RawEntry()
@ -61,6 +48,8 @@ func HomepageConfig() homepage.Config {
return return
} }
item.Alias = alias
if item.Name == "" { if item.Name == "" {
item.Name = strutils.Title( item.Name = strutils.Title(
strings.ReplaceAll( strings.ReplaceAll(
@ -102,13 +91,7 @@ func HomepageConfig() homepage.Config {
item.SourceType = string(proxy.ProviderTypeFile) item.SourceType = string(proxy.ProviderTypeFile)
} }
if item.URL == "" {
if len(domains) > 0 {
item.URL = fmt.Sprintf("%s://%s%s:%s", proto, strings.ToLower(alias), domains[0], port)
}
}
item.AltURL = r.TargetURL().String() item.AltURL = r.TargetURL().String()
hpCfg.Add(item) hpCfg.Add(item)
}) })
return hpCfg return hpCfg

View file

@ -7,13 +7,14 @@ type (
Item struct { Item struct {
Show bool `json:"show"` Show bool `json:"show"`
Name string `json:"name"` Name string `json:"name"` // display name
Icon string `json:"icon"` Icon string `json:"icon"`
URL string `json:"url"` // alias + domain URL string `json:"url"` // alias + domain
Category string `json:"category"` Category string `json:"category"`
Description string `json:"description" aliases:"desc"` Description string `json:"description" aliases:"desc"`
WidgetConfig map[string]any `json:"widget_config" aliases:"widget"` WidgetConfig map[string]any `json:"widget_config" aliases:"widget"`
Alias string `json:"alias"` // proxy alias
SourceType string `json:"source_type"` SourceType string `json:"source_type"`
AltURL string `json:"alt_url"` // original proxy target AltURL string `json:"alt_url"` // original proxy target
} }