mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
fix: Endpoins missing in clashapi
This commit is contained in:
parent
bfe7c6bdda
commit
4fcee9d137
@ -83,14 +83,35 @@ func proxyInfo(server *Server, detour adapter.Outbound) *badjson.JSONObject {
|
||||
return &info
|
||||
}
|
||||
|
||||
func endpointInfo(server *Server, endpoint adapter.Endpoint) *badjson.JSONObject {
|
||||
var info badjson.JSONObject
|
||||
|
||||
info.Put("type", C.ProxyDisplayName(endpoint.Type()))
|
||||
info.Put("name", endpoint.Tag())
|
||||
info.Put("udp", common.Contains(endpoint.Network(), N.NetworkUDP))
|
||||
delayHistory := server.urlTestHistory.LoadURLTestHistory(adapter.OutboundTag(endpoint))
|
||||
|
||||
if delayHistory != nil {
|
||||
info.Put("history", []*urltest.History{delayHistory})
|
||||
} else {
|
||||
info.Put("history", []*urltest.History{})
|
||||
}
|
||||
|
||||
return &info
|
||||
}
|
||||
|
||||
|
||||
func getProxies(server *Server) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var proxyMap badjson.JSONObject
|
||||
outbounds := common.Filter(server.outboundManager.Outbounds(), func(detour adapter.Outbound) bool {
|
||||
return detour.Tag() != ""
|
||||
})
|
||||
endpoints := common.Filter(server.endpointManager.Endpoints(), func(detour adapter.Endpoint) bool {
|
||||
return detour.Tag() != ""
|
||||
})
|
||||
|
||||
allProxies := make([]string, 0, len(outbounds))
|
||||
allProxies := make([]string, 0, len(outbounds) + len(endpoints))
|
||||
|
||||
for _, detour := range outbounds {
|
||||
switch detour.Type() {
|
||||
@ -100,6 +121,10 @@ func getProxies(server *Server) func(w http.ResponseWriter, r *http.Request) {
|
||||
allProxies = append(allProxies, detour.Tag())
|
||||
}
|
||||
|
||||
for _, endpoint := range endpoints {
|
||||
allProxies = append(allProxies, endpoint.Tag())
|
||||
}
|
||||
|
||||
defaultTag := server.outboundManager.Default().Tag()
|
||||
|
||||
sort.SliceStable(allProxies, func(i, j int) bool {
|
||||
@ -125,6 +150,17 @@ func getProxies(server *Server) func(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
proxyMap.Put(tag, proxyInfo(server, detour))
|
||||
}
|
||||
|
||||
for i, endpoint := range endpoints {
|
||||
var tag string
|
||||
if endpoint.Tag() == "" {
|
||||
tag = F.ToString(i)
|
||||
} else {
|
||||
tag = endpoint.Tag()
|
||||
}
|
||||
proxyMap.Put(tag, endpointInfo(server, endpoint))
|
||||
}
|
||||
|
||||
var responseMap badjson.JSONObject
|
||||
responseMap.Put("proxies", &proxyMap)
|
||||
response, err := responseMap.MarshalJSON()
|
||||
|
@ -43,6 +43,7 @@ type Server struct {
|
||||
ctx context.Context
|
||||
router adapter.Router
|
||||
outboundManager adapter.OutboundManager
|
||||
endpointManager adapter.EndpointManager
|
||||
logger log.Logger
|
||||
httpServer *http.Server
|
||||
trafficManager *trafficontrol.Manager
|
||||
@ -64,6 +65,7 @@ func NewServer(ctx context.Context, logFactory log.ObservableFactory, options op
|
||||
ctx: ctx,
|
||||
router: service.FromContext[adapter.Router](ctx),
|
||||
outboundManager: service.FromContext[adapter.OutboundManager](ctx),
|
||||
endpointManager: service.FromContext[adapter.EndpointManager](ctx),
|
||||
logger: logFactory.NewLogger("clash-api"),
|
||||
httpServer: &http.Server{
|
||||
Addr: options.ExternalController,
|
||||
|
Loading…
x
Reference in New Issue
Block a user