forked from mirror/serenity
Fix rule-set template
This commit is contained in:
parent
6da3a8eaee
commit
6dcfa706eb
@ -4,13 +4,13 @@ RuleSet generate configuration.
|
|||||||
|
|
||||||
### Structure
|
### Structure
|
||||||
|
|
||||||
=== "Default"
|
=== "Original"
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "", // optional
|
"type": "remote", // or local
|
||||||
|
|
||||||
... // Default Fields
|
... // Original Fields
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ RuleSet generate configuration.
|
|||||||
"type": "github",
|
"type": "github",
|
||||||
"repository": "",
|
"repository": "",
|
||||||
"path": "",
|
"path": "",
|
||||||
"rule-set": []
|
"rule_set": []
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ RuleSet generate configuration.
|
|||||||
"repository": "SagerNet/sing-geosite",
|
"repository": "SagerNet/sing-geosite",
|
||||||
"path": "rule-set",
|
"path": "rule-set",
|
||||||
"prefix": "geosite-",
|
"prefix": "geosite-",
|
||||||
"rule-set": [
|
"rule_set": [
|
||||||
"apple",
|
"apple",
|
||||||
"microsoft",
|
"microsoft",
|
||||||
"openai"
|
"openai"
|
||||||
@ -49,7 +49,7 @@ RuleSet generate configuration.
|
|||||||
"repository": "MetaCubeX/meta-rules-dat",
|
"repository": "MetaCubeX/meta-rules-dat",
|
||||||
"path": "sing/geo/geosite",
|
"path": "sing/geo/geosite",
|
||||||
"prefix": "geosite-",
|
"prefix": "geosite-",
|
||||||
"rule-set": [
|
"rule_set": [
|
||||||
"apple",
|
"apple",
|
||||||
"microsoft",
|
"microsoft",
|
||||||
"openai"
|
"openai"
|
||||||
@ -57,7 +57,7 @@ RuleSet generate configuration.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Default Fields
|
### Original Fields
|
||||||
|
|
||||||
See [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/).
|
See [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/).
|
||||||
|
|
||||||
@ -75,6 +75,6 @@ Branch and directory path, `rule-set` or `sing/geo/<geoip/geosite>`.
|
|||||||
|
|
||||||
File prefix, `geoip-` or `geosite-`.
|
File prefix, `geoip-` or `geosite-`.
|
||||||
|
|
||||||
#### rule-set
|
#### rule_set
|
||||||
|
|
||||||
RuleSet name list.
|
RuleSet name list.
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
C "github.com/sagernet/serenity/constant"
|
C "github.com/sagernet/serenity/constant"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
"github.com/sagernet/sing-dns"
|
"github.com/sagernet/sing-dns"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
|
||||||
"github.com/sagernet/sing/common/json"
|
"github.com/sagernet/sing/common/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,24 +79,12 @@ type _RuleSet struct {
|
|||||||
|
|
||||||
type RuleSet _RuleSet
|
type RuleSet _RuleSet
|
||||||
|
|
||||||
func (r *RuleSet) RawOptions() (any, error) {
|
|
||||||
switch r.Type {
|
|
||||||
case C.RuleSetTypeDefault, "":
|
|
||||||
r.Type = ""
|
|
||||||
return &r.DefaultOptions, nil
|
|
||||||
case C.RuleSetTypeGitHub:
|
|
||||||
return &r.GitHubOptions, nil
|
|
||||||
default:
|
|
||||||
return nil, E.New("unknown rule set type", r.Type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleSet) MarshalJSON() ([]byte, error) {
|
func (r *RuleSet) MarshalJSON() ([]byte, error) {
|
||||||
rawOptions, err := r.RawOptions()
|
if r.Type == C.RuleSetTypeGitHub {
|
||||||
if err != nil {
|
return option.MarshallObjects((*_RuleSet)(r), r.GitHubOptions)
|
||||||
return nil, err
|
} else {
|
||||||
|
return json.Marshal(r.DefaultOptions)
|
||||||
}
|
}
|
||||||
return option.MarshallObjects((*_RuleSet)(r), rawOptions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
||||||
@ -105,11 +92,11 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rawOptions, err := r.RawOptions()
|
if r.Type == C.RuleSetTypeGitHub {
|
||||||
if err != nil {
|
return option.UnmarshallExcluded(bytes, (*_RuleSet)(r), &r.GitHubOptions)
|
||||||
return err
|
} else {
|
||||||
|
return json.Unmarshal(bytes, &r.DefaultOptions)
|
||||||
}
|
}
|
||||||
return option.UnmarshallExcluded(bytes, (*_RuleSet)(r), rawOptions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type GitHubRuleSetOptions struct {
|
type GitHubRuleSetOptions struct {
|
||||||
|
@ -96,10 +96,7 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *boxOption.Op
|
|||||||
func (t *Template) renderRuleSet(ruleSets []option.RuleSet) []boxOption.RuleSet {
|
func (t *Template) renderRuleSet(ruleSets []option.RuleSet) []boxOption.RuleSet {
|
||||||
var result []boxOption.RuleSet
|
var result []boxOption.RuleSet
|
||||||
for _, ruleSet := range ruleSets {
|
for _, ruleSet := range ruleSets {
|
||||||
switch ruleSet.Type {
|
if ruleSet.Type == constant.RuleSetTypeGitHub {
|
||||||
case constant.RuleSetTypeDefault, "":
|
|
||||||
result = append(result, ruleSet.DefaultOptions)
|
|
||||||
case constant.RuleSetTypeGitHub:
|
|
||||||
var (
|
var (
|
||||||
downloadURL string
|
downloadURL string
|
||||||
downloadDetour string
|
downloadDetour string
|
||||||
@ -133,6 +130,8 @@ func (t *Template) renderRuleSet(ruleSets []option.RuleSet) []boxOption.RuleSet
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
result = append(result, ruleSet.DefaultOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user