forked from mirror/serenity
Convert ruleset type github to more editable type url
This commit is contained in:
parent
9a11d69d63
commit
7be25fb1c0
@ -2,5 +2,5 @@ package constant
|
||||
|
||||
const (
|
||||
RuleSetTypeDefault = "default"
|
||||
RuleSetTypeGitHub = "github"
|
||||
RuleSetTypeURL = "url"
|
||||
)
|
||||
|
@ -1,14 +1,15 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
M "github.com/sagernet/serenity/common/metadata"
|
||||
"github.com/sagernet/serenity/constant"
|
||||
"github.com/sagernet/serenity/option"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
boxOption "github.com/sagernet/sing-box/option"
|
||||
)
|
||||
|
||||
func (t *Template) renderGeoResources(metadata M.Metadata, options *boxOption.Options) {
|
||||
func (t *Template) renderGeoResources(_ M.Metadata, options *boxOption.Options) {
|
||||
if len(t.CustomRuleSet) == 0 {
|
||||
var (
|
||||
downloadURL string
|
||||
@ -63,43 +64,27 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *boxOption.Op
|
||||
func (t *Template) renderRuleSet(ruleSets []option.RuleSet) []boxOption.RuleSet {
|
||||
var result []boxOption.RuleSet
|
||||
for _, ruleSet := range ruleSets {
|
||||
if ruleSet.Type == constant.RuleSetTypeGitHub {
|
||||
var (
|
||||
downloadURL string
|
||||
downloadDetour string
|
||||
branchSplit string
|
||||
)
|
||||
if t.EnableJSDelivr {
|
||||
downloadURL = "https://testingcf.jsdelivr.net/gh/"
|
||||
if t.DirectTag != "" {
|
||||
downloadDetour = t.DirectTag
|
||||
} else {
|
||||
downloadDetour = DefaultDirectTag
|
||||
}
|
||||
branchSplit = "@"
|
||||
} else {
|
||||
downloadURL = "https://raw.githubusercontent.com/"
|
||||
branchSplit = "/"
|
||||
}
|
||||
|
||||
for _, code := range ruleSet.GitHubOptions.RuleSet {
|
||||
result = append(result, boxOption.RuleSet{
|
||||
Type: C.RuleSetTypeRemote,
|
||||
Tag: ruleSet.GitHubOptions.Prefix + code,
|
||||
Format: C.RuleSetFormatBinary,
|
||||
RemoteOptions: boxOption.RemoteRuleSet{
|
||||
URL: downloadURL +
|
||||
ruleSet.GitHubOptions.Repository +
|
||||
branchSplit +
|
||||
ruleSet.GitHubOptions.Path +
|
||||
code + ".srs",
|
||||
DownloadDetour: downloadDetour,
|
||||
},
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if ruleSet.Type == "remote" {
|
||||
result = append(result, ruleSet.DefaultOptions)
|
||||
}
|
||||
|
||||
for tagname, filename := range ruleSet.URLOptions.RuleSet {
|
||||
url, _ := url.JoinPath(ruleSet.URLOptions.Base, filename)
|
||||
var tag string
|
||||
if ruleSet.URLOptions.Prefix != "" {
|
||||
tag = ruleSet.URLOptions.Prefix + "-" + tagname
|
||||
} else {
|
||||
tag = tagname
|
||||
}
|
||||
result = append(result, boxOption.RuleSet{
|
||||
Type: C.RuleSetTypeRemote,
|
||||
Tag: tag,
|
||||
Format: C.RuleSetFormatBinary,
|
||||
RemoteOptions: boxOption.RemoteRuleSet{
|
||||
URL: url,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user