feat: support merging multiple subscriptions
This commit is contained in:
82
internal/automation/types.go
Normal file
82
internal/automation/types.go
Normal file
@ -0,0 +1,82 @@
|
||||
// Package automation implements the `ssm:` automation block that can be
|
||||
// added to core-config.yaml, letting users declaratively:
|
||||
//
|
||||
// 1. build a new proxy-group from proxies matching a subscription/keyword
|
||||
// filter ("proxy-groups"),
|
||||
// 2. build a new proxy-group from proxies whose name encodes a rate/
|
||||
// multiplier extracted via regexp, filtered by a comparator
|
||||
// ("rate-filters"), and
|
||||
// 3. append/prepend/replace an arbitrary path in the generated config
|
||||
// ("patches").
|
||||
//
|
||||
// The `ssm:` key itself is metadata for this tool, not a real mihomo/clash
|
||||
// config key, so it's always stripped out of the generated config before
|
||||
// writing (see internal/corecfg.Apply).
|
||||
package automation
|
||||
|
||||
// ProxyRef describes a single proxy in the pool merged from every active
|
||||
// subscription.
|
||||
type ProxyRef struct {
|
||||
// OriginalName is the proxy's name as it appeared in its subscription,
|
||||
// before subscription-name prefixing. Keyword and rate-pattern matching
|
||||
// both operate on this.
|
||||
OriginalName string
|
||||
// DisplayName is OriginalName prefixed with its source subscription's
|
||||
// name (e.g. "home-sub | HK 01"), which is what actually appears in the
|
||||
// generated config's proxies list and must be used when referencing
|
||||
// this proxy from a built proxy-group.
|
||||
DisplayName string
|
||||
// Subscription is the name of the subscription this proxy came from.
|
||||
Subscription string
|
||||
}
|
||||
|
||||
// MatchRule narrows which proxies a proxy-groups/rate-filters rule
|
||||
// considers. Both fields are optional; an empty/omitted field imposes no
|
||||
// restriction on that dimension. Multiple entries within a field are OR'd
|
||||
// together.
|
||||
type MatchRule struct {
|
||||
Subscriptions []string `yaml:"subscriptions"`
|
||||
NameContains []string `yaml:"name-contains"`
|
||||
}
|
||||
|
||||
// ProxyGroupRule defines a new proxy-group built from every proxy matching
|
||||
// Match. Any YAML fields beyond name/type/match (e.g. url, interval,
|
||||
// tolerance) are passed through verbatim onto the generated proxy-group.
|
||||
type ProxyGroupRule struct {
|
||||
Name string `yaml:"name"`
|
||||
Type string `yaml:"type"`
|
||||
Match MatchRule `yaml:"match"`
|
||||
Extra map[string]interface{} `yaml:",inline"`
|
||||
}
|
||||
|
||||
// RateFilterRule defines a new proxy-group built from proxies whose
|
||||
// (pre-prefix) name matches Pattern — a regexp whose first capture group is
|
||||
// parsed as a float rate — and whose rate satisfies "rate Operator Value".
|
||||
// Proxies whose name doesn't match Pattern at all are excluded. Any YAML
|
||||
// fields beyond the recognized ones are passed through onto the generated
|
||||
// proxy-group, same as ProxyGroupRule.
|
||||
type RateFilterRule struct {
|
||||
Name string `yaml:"name"`
|
||||
Type string `yaml:"type"`
|
||||
Pattern string `yaml:"pattern"`
|
||||
Operator string `yaml:"operator"`
|
||||
Value float64 `yaml:"value"`
|
||||
Match MatchRule `yaml:"match"`
|
||||
Extra map[string]interface{} `yaml:",inline"`
|
||||
}
|
||||
|
||||
// PatchRule appends/prepends/replaces Value at Path (a dot/bracket path
|
||||
// like "dns.nameserver" or "proxy-groups[0].proxies") in the generated
|
||||
// config.
|
||||
type PatchRule struct {
|
||||
Path string `yaml:"path"`
|
||||
Op string `yaml:"op"`
|
||||
Value interface{} `yaml:"value"`
|
||||
}
|
||||
|
||||
// Config is the full `ssm:` automation block parsed from core-config.yaml.
|
||||
type Config struct {
|
||||
ProxyGroups []ProxyGroupRule `yaml:"proxy-groups"`
|
||||
RateFilters []RateFilterRule `yaml:"rate-filters"`
|
||||
Patches []PatchRule `yaml:"patches"`
|
||||
}
|
||||
Reference in New Issue
Block a user