feat: evolve rate-filter to a more generic filter
This commit is contained in:
@ -16,18 +16,21 @@ import (
|
||||
// rename. References to anything else (DIRECT, REJECT, a proxy-provider
|
||||
// name, ...) are left untouched.
|
||||
//
|
||||
// Returns a ProxyRef per proxy, for later ssm matching/grouping.
|
||||
func PrefixProxyNames(subscriptionName string, data map[string]interface{}) []ProxyRef {
|
||||
// Returns a ProxyRef per proxy and, separately, a ProxyRef per proxy-group —
|
||||
// both usable for later ssm matching/grouping, so a `match.name-pattern` can
|
||||
// target either a raw proxy or one of the subscription's own groups (e.g.
|
||||
// its default selector).
|
||||
func PrefixProxyNames(subscriptionName string, data map[string]interface{}) (proxies []ProxyRef, groups []ProxyRef) {
|
||||
// Original name (of either a proxy or a proxy-group) -> prefixed
|
||||
// display name. Clash requires proxy and group names to share a single
|
||||
// namespace within one config, so a single map is correct here too.
|
||||
rename := make(map[string]string)
|
||||
|
||||
refs := renameProxies(subscriptionName, data, rename)
|
||||
renameProxyGroups(subscriptionName, data, rename)
|
||||
proxies = renameProxies(subscriptionName, data, rename)
|
||||
groups = renameProxyGroups(subscriptionName, data, rename)
|
||||
RewriteReferences(data, rename)
|
||||
|
||||
return refs
|
||||
return proxies, groups
|
||||
}
|
||||
|
||||
// RewriteReferences rewrites every reference to a renamed proxy or
|
||||
@ -71,7 +74,8 @@ func renameProxies(subscriptionName string, data map[string]interface{}, rename
|
||||
return refs
|
||||
}
|
||||
|
||||
func renameProxyGroups(subscriptionName string, data map[string]interface{}, rename map[string]string) {
|
||||
func renameProxyGroups(subscriptionName string, data map[string]interface{}, rename map[string]string) []ProxyRef {
|
||||
var refs []ProxyRef
|
||||
for _, group := range proxyGroupMaps(data) {
|
||||
name, ok := group["name"].(string)
|
||||
if !ok {
|
||||
@ -80,7 +84,14 @@ func renameProxyGroups(subscriptionName string, data map[string]interface{}, ren
|
||||
display := fmt.Sprintf("%s | %s", subscriptionName, name)
|
||||
group["name"] = display
|
||||
rename[name] = display
|
||||
|
||||
refs = append(refs, ProxyRef{
|
||||
OriginalName: name,
|
||||
DisplayName: display,
|
||||
Subscription: subscriptionName,
|
||||
})
|
||||
}
|
||||
return refs
|
||||
}
|
||||
|
||||
func rewriteGroupProxyReferences(data map[string]interface{}, rename map[string]string) {
|
||||
|
||||
Reference in New Issue
Block a user