mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 08:47:09 +00:00
chore: move proxiesWithProviders to hub/route internal to disallow external usage of this poorly implemented function
This commit is contained in:
@@ -46,7 +46,7 @@ func parseProxyName(next http.Handler) http.Handler {
|
||||
func findProxyByName(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
name := r.Context().Value(CtxKeyProxyName).(string)
|
||||
proxies := tunnel.ProxiesWithProviders()
|
||||
proxies := proxiesWithProviders()
|
||||
proxy, exist := proxies[name]
|
||||
if !exist {
|
||||
render.Status(r, http.StatusNotFound)
|
||||
@@ -60,7 +60,7 @@ func findProxyByName(next http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
func getProxies(w http.ResponseWriter, r *http.Request) {
|
||||
proxies := tunnel.ProxiesWithProviders()
|
||||
proxies := proxiesWithProviders()
|
||||
render.JSON(w, r, render.M{
|
||||
"proxies": proxies,
|
||||
})
|
||||
@@ -158,3 +158,21 @@ func unfixedProxy(w http.ResponseWriter, r *http.Request) {
|
||||
render.Status(r, http.StatusBadRequest)
|
||||
render.JSON(w, r, ErrBadRequest)
|
||||
}
|
||||
|
||||
// proxiesWithProviders merges all proxies from tunnel
|
||||
//
|
||||
// Deprecated: This function is poorly implemented and should not be called by any new code.
|
||||
// It is left here only to ensure the compatibility of the output of the existing RESTful API.
|
||||
func proxiesWithProviders() map[string]C.Proxy {
|
||||
allProxies := make(map[string]C.Proxy)
|
||||
for name, proxy := range tunnel.Proxies() {
|
||||
allProxies[name] = proxy
|
||||
}
|
||||
for _, p := range tunnel.Providers() {
|
||||
for _, proxy := range p.Proxies() {
|
||||
name := proxy.Name()
|
||||
allProxies[name] = proxy
|
||||
}
|
||||
}
|
||||
return allProxies
|
||||
}
|
||||
|
||||
@@ -208,20 +208,6 @@ func Proxies() map[string]C.Proxy {
|
||||
return proxies
|
||||
}
|
||||
|
||||
func ProxiesWithProviders() map[string]C.Proxy {
|
||||
allProxies := make(map[string]C.Proxy)
|
||||
for name, proxy := range proxies {
|
||||
allProxies[name] = proxy
|
||||
}
|
||||
for _, p := range providers {
|
||||
for _, proxy := range p.Proxies() {
|
||||
name := proxy.Name()
|
||||
allProxies[name] = proxy
|
||||
}
|
||||
}
|
||||
return allProxies
|
||||
}
|
||||
|
||||
// Providers return all compatible providers
|
||||
func Providers() map[string]P.ProxyProvider {
|
||||
return providers
|
||||
|
||||
Reference in New Issue
Block a user