forked from mirror/serenity
Rewrite subscription.process
This commit is contained in:
parent
cf6908fdf8
commit
56920ed988
@ -11,6 +11,8 @@
|
||||
"exclude": [],
|
||||
"filter_type": [],
|
||||
"exclude_type": [],
|
||||
"invert": false,
|
||||
"remove": false,
|
||||
"rename": {},
|
||||
"remove_emoji": false,
|
||||
"rewrite_multiplex": {}
|
||||
@ -56,19 +58,27 @@ Process rules.
|
||||
|
||||
#### process.filter
|
||||
|
||||
Regexp filter rules, non-matching outbounds will be removed.
|
||||
Regexp filter rules, match outbound tag name.
|
||||
|
||||
#### process.exclude
|
||||
|
||||
Regexp exclude rules, matching outbounds will be removed.
|
||||
Regexp exclude rules, match outbound tag name.
|
||||
|
||||
#### process.filter_type
|
||||
|
||||
Outbound type filter rules, non-matching outbounds will be removed.
|
||||
Filter rules, match outbound type.
|
||||
|
||||
#### process.exclude_type
|
||||
|
||||
Outbound type exclude rules, matching outbounds will be removed.
|
||||
Exclude rules, match outbound type.
|
||||
|
||||
#### process.invert
|
||||
|
||||
Invert filter results.
|
||||
|
||||
#### process.remove
|
||||
|
||||
Remove outbounds that match the rules.
|
||||
|
||||
#### process.rename
|
||||
|
||||
|
@ -66,6 +66,8 @@ type OutboundProcessOptions struct {
|
||||
Exclude option.Listable[string] `json:"exclude,omitempty"`
|
||||
FilterType option.Listable[string] `json:"filter_type,omitempty"`
|
||||
ExcludeType option.Listable[string] `json:"exclude_type,omitempty"`
|
||||
Invert bool `json:"invert,omitempty"`
|
||||
Remove bool `json:"remove,omitempty"`
|
||||
Rename *badjson.TypedMap[string, string] `json:"rename,omitempty"`
|
||||
RemoveEmoji bool `json:"remove_emoji,omitempty"`
|
||||
RewriteMultiplex *option.OutboundMultiplexOptions `json:"rewrite_multiplex,omitempty"`
|
||||
|
@ -67,29 +67,44 @@ func (o *ProcessOptions) Process(outbounds []boxOption.Outbound) []boxOption.Out
|
||||
newOutbounds := make([]boxOption.Outbound, 0, len(outbounds))
|
||||
renameResult := make(map[string]string)
|
||||
for _, outbound := range outbounds {
|
||||
if len(o.filter) > 0 {
|
||||
if !common.Any(o.filter, func(it *regexp.Regexp) bool {
|
||||
return it.MatchString(outbound.Tag)
|
||||
}) {
|
||||
continue
|
||||
var inProcess bool
|
||||
if len(o.filter) == 0 && len(o.FilterType) == 0 && len(o.exclude) == 0 && len(o.ExcludeType) == 0 {
|
||||
inProcess = true
|
||||
} else {
|
||||
if len(o.filter) > 0 {
|
||||
if !common.Any(o.filter, func(it *regexp.Regexp) bool {
|
||||
return it.MatchString(outbound.Tag)
|
||||
}) {
|
||||
inProcess = true
|
||||
}
|
||||
}
|
||||
if !inProcess && len(o.FilterType) > 0 {
|
||||
if !common.Contains(o.FilterType, outbound.Type) {
|
||||
inProcess = true
|
||||
}
|
||||
}
|
||||
if !inProcess && len(o.exclude) > 0 {
|
||||
if common.Any(o.exclude, func(it *regexp.Regexp) bool {
|
||||
return it.MatchString(outbound.Tag)
|
||||
}) {
|
||||
inProcess = true
|
||||
}
|
||||
}
|
||||
if !inProcess && len(o.ExcludeType) > 0 {
|
||||
if common.Contains(o.ExcludeType, outbound.Type) {
|
||||
inProcess = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(o.FilterType) > 0 {
|
||||
if !common.Contains(o.FilterType, outbound.Type) {
|
||||
continue
|
||||
}
|
||||
if o.Invert {
|
||||
inProcess = !inProcess
|
||||
}
|
||||
if len(o.exclude) > 0 {
|
||||
if common.Any(o.exclude, func(it *regexp.Regexp) bool {
|
||||
return it.MatchString(outbound.Tag)
|
||||
}) {
|
||||
continue
|
||||
}
|
||||
if !inProcess {
|
||||
newOutbounds = append(newOutbounds, outbound)
|
||||
continue
|
||||
}
|
||||
if len(o.ExcludeType) > 0 {
|
||||
if common.Contains(o.ExcludeType, outbound.Type) {
|
||||
continue
|
||||
}
|
||||
if o.Remove {
|
||||
continue
|
||||
}
|
||||
originTag := outbound.Tag
|
||||
if len(o.rename) > 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user