Unify parts of the model with MetaCubeX.

This commit is contained in:
2025-06-12 14:19:00 +10:00
parent 0c8bbac2e6
commit f88ae52a29
24 changed files with 590 additions and 353 deletions

View File

@ -56,11 +56,11 @@ func AddProxy(
if !proxyTypes[proxy.Type] {
continue
}
sub.Proxies = append(sub.Proxies, proxy)
sub.Proxy = append(sub.Proxy, proxy)
haveProxyGroup := false
countryName := GetContryName(proxy.Name)
for i := range sub.ProxyGroups {
group := &sub.ProxyGroups[i]
for i := range sub.ProxyGroup {
group := &sub.ProxyGroup[i]
if group.Name == countryName {
group.Proxies = append(group.Proxies, proxy.Name)
group.Size++
@ -90,7 +90,7 @@ func AddProxy(
Size: 1,
}
}
sub.ProxyGroups = append(sub.ProxyGroups, newGroup)
sub.ProxyGroup = append(sub.ProxyGroup, newGroup)
}
}
}

View File

@ -10,10 +10,10 @@ import (
func PrependRuleProvider(
sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
) {
if sub.RuleProviders == nil {
sub.RuleProviders = make(map[string]model.RuleProvider)
if sub.RuleProvider == nil {
sub.RuleProvider = make(map[string]model.RuleProvider)
}
sub.RuleProviders[providerName] = provider
sub.RuleProvider[providerName] = provider
PrependRules(
sub,
fmt.Sprintf("RULE-SET,%s,%s", providerName, group),
@ -23,29 +23,29 @@ func PrependRuleProvider(
func AppenddRuleProvider(
sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
) {
if sub.RuleProviders == nil {
sub.RuleProviders = make(map[string]model.RuleProvider)
if sub.RuleProvider == nil {
sub.RuleProvider = make(map[string]model.RuleProvider)
}
sub.RuleProviders[providerName] = provider
sub.RuleProvider[providerName] = provider
AppendRules(sub, fmt.Sprintf("RULE-SET,%s,%s", providerName, group))
}
func PrependRules(sub *model.Subscription, rules ...string) {
if sub.Rules == nil {
sub.Rules = make([]string, 0)
if sub.Rule == nil {
sub.Rule = make([]string, 0)
}
sub.Rules = append(rules, sub.Rules...)
sub.Rule = append(rules, sub.Rule...)
}
func AppendRules(sub *model.Subscription, rules ...string) {
if sub.Rules == nil {
sub.Rules = make([]string, 0)
if sub.Rule == nil {
sub.Rule = make([]string, 0)
}
matchRule := sub.Rules[len(sub.Rules)-1]
matchRule := sub.Rule[len(sub.Rule)-1]
if strings.Contains(matchRule, "MATCH") {
sub.Rules = append(sub.Rules[:len(sub.Rules)-1], rules...)
sub.Rules = append(sub.Rules, matchRule)
sub.Rule = append(sub.Rule[:len(sub.Rule)-1], rules...)
sub.Rule = append(sub.Rule, matchRule)
return
}
sub.Rules = append(sub.Rules, rules...)
sub.Rule = append(sub.Rule, rules...)
}

View File

@ -170,7 +170,7 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
newProxies = p
}
} else {
newProxies = sub.Proxies
newProxies = sub.Proxy
}
if subName != "" {
for i := range newProxies {
@ -180,7 +180,7 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
proxyList = append(proxyList, newProxies...)
}
if len(query.Proxies) != 0 {
if len(query.Proxy) != 0 {
proxyList = append(proxyList, parser.ParseProxies(query.Proxies...)...)
}
@ -265,15 +265,15 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
switch query.Sort {
case "sizeasc":
sort.Sort(model.ProxyGroupsSortBySize(t.ProxyGroups))
sort.Sort(model.ProxyGroupsSortBySize(t.ProxyGroup))
case "sizedesc":
sort.Sort(sort.Reverse(model.ProxyGroupsSortBySize(t.ProxyGroups)))
sort.Sort(sort.Reverse(model.ProxyGroupsSortBySize(t.ProxyGroup)))
case "nameasc":
sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroups))
sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroup))
case "namedesc":
sort.Sort(sort.Reverse(model.ProxyGroupsSortByName(t.ProxyGroups)))
sort.Sort(sort.Reverse(model.ProxyGroupsSortByName(t.ProxyGroup)))
default:
sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroups))
sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroup))
}
MergeSubAndTemplate(temp, t, query.IgnoreCountryGrooup)
@ -328,7 +328,7 @@ func FetchSubscriptionUserInfo(url string, userAgent string, retryTimes int) (st
func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg bool) {
var countryGroupNames []string
for _, proxyGroup := range sub.ProxyGroups {
for _, proxyGroup := range sub.ProxyGroup {
if proxyGroup.IsCountryGrop {
countryGroupNames = append(
countryGroupNames, proxyGroup.Name,
@ -336,27 +336,27 @@ func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg
}
}
var proxyNames []string
for _, proxy := range sub.Proxies {
for _, proxy := range sub.Proxy {
proxyNames = append(proxyNames, proxy.Name)
}
temp.Proxies = append(temp.Proxies, sub.Proxies...)
temp.Proxy = append(temp.Proxy, sub.Proxy...)
for i := range temp.ProxyGroups {
if temp.ProxyGroups[i].IsCountryGrop {
for i := range temp.ProxyGroup {
if temp.ProxyGroup[i].IsCountryGrop {
continue
}
newProxies := make([]string, 0)
countryGroupMap := make(map[string]model.ProxyGroup)
for _, v := range sub.ProxyGroups {
for _, v := range sub.ProxyGroup {
if v.IsCountryGrop {
countryGroupMap[v.Name] = v
}
}
for j := range temp.ProxyGroups[i].Proxies {
for j := range temp.ProxyGroup[i].Proxies {
reg := regexp.MustCompile("<(.*?)>")
if reg.Match([]byte(temp.ProxyGroups[i].Proxies[j])) {
key := reg.FindStringSubmatch(temp.ProxyGroups[i].Proxies[j])[1]
if reg.Match([]byte(temp.ProxyGroup[i].Proxies[j])) {
key := reg.FindStringSubmatch(temp.ProxyGroup[i].Proxies[j])[1]
switch key {
case "all":
newProxies = append(newProxies, proxyNames...)
@ -374,12 +374,12 @@ func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg
}
}
} else {
newProxies = append(newProxies, temp.ProxyGroups[i].Proxies[j])
newProxies = append(newProxies, temp.ProxyGroup[i].Proxies[j])
}
}
temp.ProxyGroups[i].Proxies = newProxies
temp.ProxyGroup[i].Proxies = newProxies
}
if !igcg {
temp.ProxyGroups = append(temp.ProxyGroups, sub.ProxyGroups...)
temp.ProxyGroup = append(temp.ProxyGroup, sub.ProxyGroup...)
}
}