mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2024-11-28 16:26:09 +03:00
fix patchProviders works abnormally when path is empty
This commit is contained in:
parent
e164e219bd
commit
36bc78070a
@ -112,7 +112,7 @@ func FetchAndValid(
|
||||
return err
|
||||
}
|
||||
|
||||
forEachProviders(rawCfg, func(index int, total int, name string, provider map[string]any) {
|
||||
forEachProviders(rawCfg, func(index int, total int, name string, provider map[string]any, prefix string) {
|
||||
bytes, _ := json.Marshal(&Status{
|
||||
Action: "FetchProviders",
|
||||
Args: []string{name},
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"cfa/native/common"
|
||||
|
||||
"github.com/metacubex/mihomo/common/utils"
|
||||
"github.com/metacubex/mihomo/config"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
@ -109,10 +110,16 @@ func patchListeners(cfg *config.RawConfig, _ string) error {
|
||||
}
|
||||
|
||||
func patchProviders(cfg *config.RawConfig, profileDir string) error {
|
||||
forEachProviders(cfg, func(index int, total int, key string, provider map[string]any) {
|
||||
if path, ok := provider["path"].(string); ok {
|
||||
provider["path"] = profileDir + "/providers/" + common.ResolveAsRoot(path)
|
||||
forEachProviders(cfg, func(index int, total int, key string, provider map[string]any, prefix string) {
|
||||
path, _ := provider["path"].(string)
|
||||
if len(path) > 0 {
|
||||
path = common.ResolveAsRoot(path)
|
||||
} else if url, ok := provider["url"].(string); ok {
|
||||
path = prefix + "/" + utils.MakeHash([]byte(url)).String() // same as C.GetPathByHash
|
||||
} else {
|
||||
return // both path and url is empty, WTF???
|
||||
}
|
||||
provider["path"] = profileDir + "/providers/" + path
|
||||
})
|
||||
|
||||
return nil
|
||||
|
@ -6,18 +6,23 @@ import (
|
||||
"github.com/metacubex/mihomo/config"
|
||||
)
|
||||
|
||||
func forEachProviders(rawCfg *config.RawConfig, fun func(index int, total int, key string, provider map[string]any)) {
|
||||
const (
|
||||
PROXIES = "proxies"
|
||||
RULES = "rules"
|
||||
)
|
||||
|
||||
func forEachProviders(rawCfg *config.RawConfig, fun func(index int, total int, key string, provider map[string]any, prefix string)) {
|
||||
total := len(rawCfg.ProxyProvider) + len(rawCfg.RuleProvider)
|
||||
index := 0
|
||||
|
||||
for k, v := range rawCfg.ProxyProvider {
|
||||
fun(index, total, k, v)
|
||||
fun(index, total, k, v, PROXIES)
|
||||
|
||||
index++
|
||||
}
|
||||
|
||||
for k, v := range rawCfg.RuleProvider {
|
||||
fun(index, total, k, v)
|
||||
fun(index, total, k, v, RULES)
|
||||
|
||||
index++
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user