Add template.post_custom_rule_set

This commit is contained in:
世界 2024-05-04 22:59:14 +08:00
parent ef68e70c06
commit 45d6d8e99b
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
3 changed files with 55 additions and 44 deletions

View File

@ -55,6 +55,7 @@
"custom_geoip": {}, "custom_geoip": {},
"custom_geosite": {}, "custom_geosite": {},
"custom_rule_set": [], "custom_rule_set": [],
"post_custom_rule_set": [],
// Experimental // Experimental
@ -242,6 +243,12 @@ List of [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/).
Default rule sets will not be generated if not empty. Default rule sets will not be generated if not empty.
#### post_custom_rule_set
List of [RuleSet](https://sing-box.sagernet.org/configuration/rule-set/).
Will be applied after default rule sets.
#### disable_cache_file #### disable_cache_file
Don't generate `cache_file` related options. Don't generate `cache_file` related options.

View File

@ -50,6 +50,7 @@ type Template struct {
CustomGeoIP *option.GeoIPOptions `json:"custom_geoip,omitempty"` CustomGeoIP *option.GeoIPOptions `json:"custom_geoip,omitempty"`
CustomGeosite *option.GeositeOptions `json:"custom_geosite,omitempty"` CustomGeosite *option.GeositeOptions `json:"custom_geosite,omitempty"`
CustomRuleSet []option.RuleSet `json:"custom_rule_set,omitempty"` CustomRuleSet []option.RuleSet `json:"custom_rule_set,omitempty"`
PostCustomRuleSet []option.RuleSet `json:"post_custom_rule_set,omitempty"`
// Experimental // Experimental
DisableCacheFile bool `json:"disable_cache_file,omitempty"` DisableCacheFile bool `json:"disable_cache_file,omitempty"`

View File

@ -38,52 +38,55 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *option.Optio
DownloadDetour: downloadDetour, DownloadDetour: downloadDetour,
} }
} }
} else if len(t.CustomRuleSet) == 0 { } else {
var ( if len(t.CustomRuleSet) == 0 {
downloadURL string var (
downloadDetour string downloadURL string
branchSplit string downloadDetour string
) branchSplit string
if t.EnableJSDelivr { )
downloadURL = "https://testingcf.jsdelivr.net/gh/" if t.EnableJSDelivr {
if t.DirectTag != "" { downloadURL = "https://testingcf.jsdelivr.net/gh/"
downloadDetour = t.DirectTag if t.DirectTag != "" {
downloadDetour = t.DirectTag
} else {
downloadDetour = DefaultDirectTag
}
branchSplit = "@"
} else { } else {
downloadDetour = DefaultDirectTag downloadURL = "https://raw.githubusercontent.com/"
branchSplit = "/"
}
options.Route.RuleSet = []option.RuleSet{
{
Type: C.RuleSetTypeRemote,
Tag: "geoip-cn",
Format: C.RuleSetFormatBinary,
RemoteOptions: option.RemoteRuleSet{
URL: downloadURL + "SagerNet/sing-geoip" + branchSplit + "rule-set/geoip-cn.srs",
DownloadDetour: downloadDetour,
},
},
{
Type: C.RuleSetTypeRemote,
Tag: "geosite-geolocation-cn",
Format: C.RuleSetFormatBinary,
RemoteOptions: option.RemoteRuleSet{
URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-cn.srs",
DownloadDetour: downloadDetour,
},
},
{
Type: C.RuleSetTypeRemote,
Tag: "geosite-geolocation-!cn",
Format: C.RuleSetFormatBinary,
RemoteOptions: option.RemoteRuleSet{
URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-!cn.srs",
DownloadDetour: downloadDetour,
},
},
} }
branchSplit = "@"
} else {
downloadURL = "https://raw.githubusercontent.com/"
branchSplit = "/"
}
options.Route.RuleSet = []option.RuleSet{
{
Type: C.RuleSetTypeRemote,
Tag: "geoip-cn",
Format: C.RuleSetFormatBinary,
RemoteOptions: option.RemoteRuleSet{
URL: downloadURL + "SagerNet/sing-geoip" + branchSplit + "rule-set/geoip-cn.srs",
DownloadDetour: downloadDetour,
},
},
{
Type: C.RuleSetTypeRemote,
Tag: "geosite-geolocation-cn",
Format: C.RuleSetFormatBinary,
RemoteOptions: option.RemoteRuleSet{
URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-cn.srs",
DownloadDetour: downloadDetour,
},
},
{
Type: C.RuleSetTypeRemote,
Tag: "geosite-geolocation-!cn",
Format: C.RuleSetFormatBinary,
RemoteOptions: option.RemoteRuleSet{
URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-geolocation-!cn.srs",
DownloadDetour: downloadDetour,
},
},
} }
options.Route.RuleSet = append(options.Route.RuleSet, t.PostCustomRuleSet...)
} }
} }