mirror of
https://github.com/xmdhs/sing-box-ruleset.git
synced 2025-02-06 04:52:42 +08:00
添加没有正则的版本
This commit is contained in:
parent
636d973b6b
commit
c734230952
6
.github/release-rule-set.sh
vendored
6
.github/release-rule-set.sh
vendored
@ -7,7 +7,11 @@ set -e -o pipefail
|
||||
|
||||
wget https://github.com/SagerNet/sing-box/releases/download/v1.8.0-alpha.11/sing-box-1.8.0-alpha.11-linux-amd64.tar.gz
|
||||
tar -zxvf sing-box-1.8.0-alpha.11-linux-amd64.tar.gz
|
||||
sing-box-1.8.0-alpha.11-linux-amd64/sing-box rule-set compile output/AdGuardSDNSFilter.json
|
||||
|
||||
for file in output/*.json; do
|
||||
sing-box-1.8.0-alpha.11-linux-amd64/sing-box rule-set compile "$file"
|
||||
done
|
||||
|
||||
|
||||
cd output
|
||||
git init
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
@ -16,10 +17,10 @@ import (
|
||||
|
||||
const AdGuardSDNSFilter = "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt"
|
||||
|
||||
func adguard(ctx context.Context, c *http.Client) (*Ruleset, error) {
|
||||
func adguard(ctx context.Context, c *http.Client) (hasReg *Ruleset, noReg *Ruleset, err error) {
|
||||
b, err := getFilter(ctx, c)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("adguard: %w", err)
|
||||
return nil, nil, fmt.Errorf("adguard: %w", err)
|
||||
}
|
||||
domain := map[string]struct{}{}
|
||||
domainRegex := map[string]struct{}{}
|
||||
@ -67,16 +68,17 @@ func adguard(ctx context.Context, c *http.Client) (*Ruleset, error) {
|
||||
domainSuffix["."+k] = struct{}{}
|
||||
}
|
||||
|
||||
r := Ruleset{}
|
||||
r.Version = 1
|
||||
r.Rules = []map[string][]any{
|
||||
rules := []map[string][]any{
|
||||
{
|
||||
"domain": toAny(domain),
|
||||
"domain_suffix": toAny(domainSuffix),
|
||||
"domain_regex": toAny(domainRegex),
|
||||
},
|
||||
}
|
||||
return &r, nil
|
||||
noRegRules := maps.Clone(rules[0])
|
||||
delete(noRegRules, "domain_regex")
|
||||
|
||||
return NewRuleSet(rules), NewRuleSet([]map[string][]any{noRegRules}), nil
|
||||
}
|
||||
|
||||
func toAny(m map[string]struct{}) []any {
|
||||
|
3
main.go
3
main.go
@ -8,12 +8,13 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
adg, err := adguard(context.Background(), &http.Client{})
|
||||
adg, adgNoReg, err := adguard(context.Background(), &http.Client{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.MkdirAll("output", 0777)
|
||||
write("output/AdGuardSDNSFilter.json", adg)
|
||||
write("output/AdGuardSDNSFilter-NoRegex.json", adgNoReg)
|
||||
}
|
||||
|
||||
func write(name string, ruleSet *Ruleset) {
|
||||
|
@ -4,3 +4,10 @@ type Ruleset struct {
|
||||
Rules []map[string][]any `json:"rules"`
|
||||
Version int `json:"version"`
|
||||
}
|
||||
|
||||
func NewRuleSet(rules []map[string][]any) *Ruleset {
|
||||
return &Ruleset{
|
||||
Rules: rules,
|
||||
Version: 1,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user