chore: better converter
Some checks are pending
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run

This commit is contained in:
wwqgtxx 2024-07-27 23:54:28 +08:00
parent 4f8a5a5f54
commit 1db3e4583b
3 changed files with 15 additions and 1 deletions

View File

@ -942,7 +942,12 @@ rule-providers:
interval: 259200
path: /path/to/save/file.yaml
type: file
rule3: # mrs类型ruleset目前仅支持domain和ipcidr可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
rule3:
# mrs类型ruleset目前仅支持domain和ipcidr(即不支持classical
# behavior=domain,format=yaml 可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
# behavior=domain,format=text 可以通过“mihomo convert-ruleset domain text XXX.text XXX.mrs”转换得到
# behavior=ipcidr,format=yaml 可以通过“mihomo convert-ruleset ipcidr yaml XXX.yaml XXX.mrs”转换得到
# behavior=ipcidr,format=text 可以通过“mihomo convert-ruleset ipcidr text XXX.text XXX.mrs”转换得到
type: http
url: "url"
format: mrs

View File

@ -3,6 +3,7 @@ package provider
import (
"errors"
"io"
"strings"
"github.com/metacubex/mihomo/component/trie"
C "github.com/metacubex/mihomo/constant"
@ -43,6 +44,10 @@ func (d *domainStrategy) Reset() {
}
func (d *domainStrategy) Insert(rule string) {
if strings.ContainsRune(rule, '/') {
log.Warnln("invalid domain:[%s]", rule)
return
}
err := d.domainTrie.Insert(rule, struct{}{})
if err != nil {
log.Warnln("invalid domain:[%s]", rule)

View File

@ -2,6 +2,7 @@ package provider
import (
"encoding/binary"
"errors"
"io"
"os"
@ -16,6 +17,9 @@ func ConvertToMrs(buf []byte, behavior P.RuleBehavior, format P.RuleFormat, w io
if err != nil {
return err
}
if strategy.Count() == 0 {
return errors.New("empty rule")
}
if _strategy, ok := strategy.(mrsRuleStrategy); ok {
var encoder *zstd.Encoder
encoder, err = zstd.NewWriter(w)