Feature: add regexp filter to use proxy provider in proxy group

This commit is contained in:
yaling888
2022-06-03 05:05:42 +08:00
parent af5bd0f65e
commit a4d135ed21
6 changed files with 210 additions and 11 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/Dreamacro/clash/adapter/outboundgroup"
"github.com/Dreamacro/clash/component/profile/cachefile"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/constant/provider"
"github.com/Dreamacro/clash/tunnel"
"github.com/go-chi/chi/v5"
@ -43,6 +44,10 @@ func findProxyByName(next http.Handler) http.Handler {
name := r.Context().Value(CtxKeyProxyName).(string)
proxies := tunnel.Proxies()
proxy, exist := proxies[name]
if !exist {
proxy, exist = findProxyInNonCompatibleProviderByName(name)
}
if !exist {
render.Status(r, http.StatusNotFound)
render.JSON(w, r, ErrNotFound)
@ -128,3 +133,20 @@ func getProxyDelay(w http.ResponseWriter, r *http.Request) {
"delay": delay,
})
}
func findProxyInNonCompatibleProviderByName(name string) (proxy C.Proxy, found bool) {
providers := tunnel.Providers()
for _, pd := range providers {
if pd.VehicleType() == provider.Compatible {
continue
}
for _, pp := range pd.Proxies() {
found = pp.Name() == name
if found {
proxy = pp
return
}
}
}
return
}