mirror of
https://github.com/xmdhs/sing-box-ruleset.git
synced 2025-02-06 04:52:42 +08:00
sort and fix some reg
This commit is contained in:
parent
d8d79fc56d
commit
636d973b6b
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AdguardTeam/urlfilter/filterlist"
|
"github.com/AdguardTeam/urlfilter/filterlist"
|
||||||
@ -54,7 +55,9 @@ func adguard(ctx context.Context, c *http.Client) (*Ruleset, error) {
|
|||||||
ruleR := strings.TrimPrefix(rule, "://")
|
ruleR := strings.TrimPrefix(rule, "://")
|
||||||
ruleR = strings.ReplaceAll(ruleR, ".", `\.`)
|
ruleR = strings.ReplaceAll(ruleR, ".", `\.`)
|
||||||
reg := strings.ReplaceAll(ruleR, "*", ".*")
|
reg := strings.ReplaceAll(ruleR, "*", ".*")
|
||||||
reg = `^(.*\.)?` + reg
|
if !strings.HasPrefix(hr.RuleText, "*") {
|
||||||
|
reg = `^(.*\.)?` + reg
|
||||||
|
}
|
||||||
if strings.HasSuffix(hr.RuleText, "^") {
|
if strings.HasSuffix(hr.RuleText, "^") {
|
||||||
reg = reg + "$"
|
reg = reg + "$"
|
||||||
}
|
}
|
||||||
@ -68,14 +71,20 @@ func adguard(ctx context.Context, c *http.Client) (*Ruleset, error) {
|
|||||||
r.Version = 1
|
r.Version = 1
|
||||||
r.Rules = []map[string][]any{
|
r.Rules = []map[string][]any{
|
||||||
{
|
{
|
||||||
"domain": lo.Map[string, any](lo.Keys(domain), func(item string, index int) any { return item }),
|
"domain": toAny(domain),
|
||||||
"domain_suffix": lo.Map[string, any](lo.Keys(domainSuffix), func(item string, index int) any { return item }),
|
"domain_suffix": toAny(domainSuffix),
|
||||||
"domain_regex": lo.Map[string, any](lo.Keys(domainRegex), func(item string, index int) any { return item }),
|
"domain_regex": toAny(domainRegex),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return &r, nil
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toAny(m map[string]struct{}) []any {
|
||||||
|
sl := lo.Keys(m)
|
||||||
|
slices.Sort(sl)
|
||||||
|
return lo.Map[string, any](sl, func(item string, index int) any { return item })
|
||||||
|
}
|
||||||
|
|
||||||
func getFilter(ctx context.Context, c *http.Client) ([]byte, error) {
|
func getFilter(ctx context.Context, c *http.Client) ([]byte, error) {
|
||||||
reps, err := http.NewRequestWithContext(ctx, "GET", AdGuardSDNSFilter, nil)
|
reps, err := http.NewRequestWithContext(ctx, "GET", AdGuardSDNSFilter, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user