From ffcd672ebf1412de62915b754150f562873579f6 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Sun, 7 Jan 2024 23:32:22 +0800 Subject: [PATCH] chore: return more information for the api --- adapter/outboundgroup/fallback.go | 6 ++++++ adapter/outboundgroup/loadbalance.go | 6 ++++++ adapter/outboundgroup/parser.go | 2 ++ adapter/outboundgroup/relay.go | 11 +++++++++-- adapter/outboundgroup/selector.go | 12 +++++++++--- adapter/outboundgroup/urltest.go | 6 ++++++ 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/adapter/outboundgroup/fallback.go b/adapter/outboundgroup/fallback.go index 488c2d34..9db97cf3 100644 --- a/adapter/outboundgroup/fallback.go +++ b/adapter/outboundgroup/fallback.go @@ -21,6 +21,8 @@ type Fallback struct { testUrl string selected string expectedStatus string + Hidden bool + Icon string } func (f *Fallback) Now() string { @@ -90,6 +92,8 @@ func (f *Fallback) MarshalJSON() ([]byte, error) { "testUrl": f.testUrl, "expectedStatus": f.expectedStatus, "fixed": f.selected, + "hidden": f.Hidden, + "icon": f.Icon, }) } @@ -165,5 +169,7 @@ func NewFallback(option *GroupCommonOption, providers []provider.ProxyProvider) disableUDP: option.DisableUDP, testUrl: option.URL, expectedStatus: option.ExpectedStatus, + Hidden: option.Hidden, + Icon: option.Icon, } } diff --git a/adapter/outboundgroup/loadbalance.go b/adapter/outboundgroup/loadbalance.go index 79b18948..976a2e89 100644 --- a/adapter/outboundgroup/loadbalance.go +++ b/adapter/outboundgroup/loadbalance.go @@ -29,6 +29,8 @@ type LoadBalance struct { strategyFn strategyFn testUrl string expectedStatus string + Hidden bool + Icon string } var errStrategy = errors.New("unsupported strategy") @@ -236,6 +238,8 @@ func (lb *LoadBalance) MarshalJSON() ([]byte, error) { "all": all, "testUrl": lb.testUrl, "expectedStatus": lb.expectedStatus, + "hidden": lb.Hidden, + "icon": lb.Icon, }) } @@ -268,5 +272,7 @@ func NewLoadBalance(option *GroupCommonOption, providers []provider.ProxyProvide disableUDP: option.DisableUDP, testUrl: option.URL, expectedStatus: option.ExpectedStatus, + Hidden: option.Hidden, + Icon: option.Icon, }, nil } diff --git a/adapter/outboundgroup/parser.go b/adapter/outboundgroup/parser.go index 3f7f9770..de20c6ea 100644 --- a/adapter/outboundgroup/parser.go +++ b/adapter/outboundgroup/parser.go @@ -37,6 +37,8 @@ type GroupCommonOption struct { IncludeAll bool `group:"include-all,omitempty"` IncludeAllProxies bool `group:"include-all-proxies,omitempty"` IncludeAllProviders bool `group:"include-all-providers,omitempty"` + Hidden bool `group:"hidden,omitempty"` + Icon string `group:"icon,omitempty"` } func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]types.ProxyProvider, AllProxies []string, AllProviders []string) (C.ProxyAdapter, error) { diff --git a/adapter/outboundgroup/relay.go b/adapter/outboundgroup/relay.go index 2b1be8a5..6a8e8bb1 100644 --- a/adapter/outboundgroup/relay.go +++ b/adapter/outboundgroup/relay.go @@ -3,6 +3,7 @@ package outboundgroup import ( "context" "encoding/json" + "github.com/metacubex/mihomo/adapter/outbound" "github.com/metacubex/mihomo/component/dialer" "github.com/metacubex/mihomo/component/proxydialer" @@ -12,6 +13,8 @@ import ( type Relay struct { *GroupBase + Hidden bool + Icon string } // DialContext implements C.ProxyAdapter @@ -106,8 +109,10 @@ func (r *Relay) MarshalJSON() ([]byte, error) { all = append(all, proxy.Name()) } return json.Marshal(map[string]any{ - "type": r.Type().String(), - "all": all, + "type": r.Type().String(), + "all": all, + "hidden": r.Hidden, + "icon": r.Icon, }) } @@ -157,5 +162,7 @@ func NewRelay(option *GroupCommonOption, providers []provider.ProxyProvider) *Re "", providers, }), + Hidden: option.Hidden, + Icon: option.Icon, } } diff --git a/adapter/outboundgroup/selector.go b/adapter/outboundgroup/selector.go index 4d06c544..3ac740f4 100644 --- a/adapter/outboundgroup/selector.go +++ b/adapter/outboundgroup/selector.go @@ -15,6 +15,8 @@ type Selector struct { *GroupBase disableUDP bool selected string + Hidden bool + Icon string } // DialContext implements C.ProxyAdapter @@ -57,9 +59,11 @@ func (s *Selector) MarshalJSON() ([]byte, error) { } return json.Marshal(map[string]any{ - "type": s.Type().String(), - "now": s.Now(), - "all": all, + "type": s.Type().String(), + "now": s.Now(), + "all": all, + "hidden": s.Hidden, + "icon": s.Icon, }) } @@ -114,5 +118,7 @@ func NewSelector(option *GroupCommonOption, providers []provider.ProxyProvider) }), selected: "COMPATIBLE", disableUDP: option.DisableUDP, + Hidden: option.Hidden, + Icon: option.Icon, } } diff --git a/adapter/outboundgroup/urltest.go b/adapter/outboundgroup/urltest.go index 2f9456fa..8439772c 100644 --- a/adapter/outboundgroup/urltest.go +++ b/adapter/outboundgroup/urltest.go @@ -33,6 +33,8 @@ type URLTest struct { expectedStatus string tolerance uint16 disableUDP bool + Hidden bool + Icon string fastNode C.Proxy fastSingle *singledo.Single[C.Proxy] } @@ -174,6 +176,8 @@ func (u *URLTest) MarshalJSON() ([]byte, error) { "testUrl": u.testUrl, "expectedStatus": u.expectedStatus, "fixed": u.selected, + "hidden": u.Hidden, + "icon": u.Icon, }) } @@ -237,6 +241,8 @@ func NewURLTest(option *GroupCommonOption, providers []provider.ProxyProvider, o disableUDP: option.DisableUDP, testUrl: option.URL, expectedStatus: option.ExpectedStatus, + Hidden: option.Hidden, + Icon: option.Icon, } for _, option := range options {