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
import (
"fmt"
"strings"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/homepage"
route "github.com/yusing/go-proxy/internal/route"
"github.com/yusing/go-proxy/internal/route/entry"
@ -33,17 +31,6 @@ func DumpProviders() map[string]*proxy.Provider {
}
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()
routes.GetHTTPRoutes().RangeAll(func(alias string, r types.HTTPRoute) {
en := r.RawEntry()
@ -61,6 +48,8 @@ func HomepageConfig() homepage.Config {
return
}
item.Alias = alias
if item.Name == "" {
item.Name = strutils.Title(
strings.ReplaceAll(
@ -102,13 +91,7 @@ func HomepageConfig() homepage.Config {
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()
hpCfg.Add(item)
})
return hpCfg

View file

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