mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-23 14:54:42 -05:00
modify: 根据Clash筛选返回配置中的节点类型
This commit is contained in:
parent
3318f5f2db
commit
918521682c
@ -5,6 +5,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"net/http"
|
||||
"sub2clash/config"
|
||||
"sub2clash/model"
|
||||
"sub2clash/validator"
|
||||
)
|
||||
|
||||
@ -15,7 +16,7 @@ func SubmodHandler(c *gin.Context) {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
sub, err := BuildSub(query, config.Default.ClashTemplate)
|
||||
sub, err := BuildSub(model.Clash, query, config.Default.ClashTemplate)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"sub2clash/validator"
|
||||
)
|
||||
|
||||
func BuildSub(query validator.SubQuery, template string) (
|
||||
func BuildSub(clashType model.ClashType, query validator.SubQuery, template string) (
|
||||
*model.Subscription, error,
|
||||
) {
|
||||
// 定义变量
|
||||
@ -67,11 +67,11 @@ func BuildSub(query validator.SubQuery, template string) (
|
||||
} else {
|
||||
proxyList = sub.Proxies
|
||||
}
|
||||
utils.AddProxy(sub, query.AutoTest, query.Lazy, query.Sort, proxyList...)
|
||||
utils.AddProxy(sub, query.AutoTest, query.Lazy, query.Sort, clashType, proxyList...)
|
||||
}
|
||||
// 处理自定义代理
|
||||
utils.AddProxy(
|
||||
sub, query.AutoTest, query.Lazy, query.Sort,
|
||||
sub, query.AutoTest, query.Lazy, query.Sort, clashType,
|
||||
utils.ParseProxy(query.Proxies...)...,
|
||||
)
|
||||
MergeSubAndTemplate(temp, sub)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"net/http"
|
||||
"sub2clash/config"
|
||||
"sub2clash/model"
|
||||
"sub2clash/validator"
|
||||
)
|
||||
|
||||
@ -16,7 +17,7 @@ func SubHandler(c *gin.Context) {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
sub, err := BuildSub(query, config.Default.MetaTemplate)
|
||||
sub, err := BuildSub(model.ClashMeta, query, config.Default.MetaTemplate)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
2
go.mod
2
go.mod
@ -6,6 +6,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/joho/godotenv v1.5.1
|
||||
go.uber.org/zap v1.25.0
|
||||
golang.org/x/text v0.13.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
@ -33,6 +34,5 @@ require (
|
||||
golang.org/x/crypto v0.13.0 // indirect
|
||||
golang.org/x/net v0.15.0 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
)
|
||||
|
29
model/clash.go
Normal file
29
model/clash.go
Normal file
@ -0,0 +1,29 @@
|
||||
package model
|
||||
|
||||
type ClashType int
|
||||
|
||||
const (
|
||||
Clash ClashType = 1 + iota
|
||||
ClashMeta
|
||||
)
|
||||
|
||||
func GetSupportProxyTypes(clashType ClashType) map[string]bool {
|
||||
if clashType == Clash {
|
||||
return map[string]bool{
|
||||
"ss": true,
|
||||
"ssr": true,
|
||||
"vmess": true,
|
||||
"trojan": true,
|
||||
}
|
||||
}
|
||||
if clashType == ClashMeta {
|
||||
return map[string]bool{
|
||||
"ss": true,
|
||||
"ssr": true,
|
||||
"vmess": true,
|
||||
"trojan": true,
|
||||
"vless": true,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
13
model/rule_provider.go
Normal file
13
model/rule_provider.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
type RuleProvider struct {
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Behavior string `yaml:"behavior,omitempty"`
|
||||
Url string `yaml:"url,omitempty"`
|
||||
Path string `yaml:"path,omitempty"`
|
||||
Interval int `yaml:"interval,omitempty"`
|
||||
}
|
||||
|
||||
type Payload struct {
|
||||
Rules []string `yaml:"payload,omitempty"`
|
||||
}
|
12
model/sub.go
12
model/sub.go
@ -12,15 +12,3 @@ type Subscription struct {
|
||||
Rules []string `yaml:"rules,omitempty"`
|
||||
RuleProviders map[string]RuleProvider `yaml:"rule-providers,omitempty,omitempty"`
|
||||
}
|
||||
|
||||
type RuleProvider struct {
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Behavior string `yaml:"behavior,omitempty"`
|
||||
Url string `yaml:"url,omitempty"`
|
||||
Path string `yaml:"path,omitempty"`
|
||||
Interval int `yaml:"interval,omitempty"`
|
||||
}
|
||||
|
||||
type Payload struct {
|
||||
Rules []string `yaml:"payload,omitempty"`
|
||||
}
|
||||
|
@ -29,12 +29,18 @@ func GetContryName(proxy model.Proxy) string {
|
||||
}
|
||||
|
||||
func AddProxy(
|
||||
sub *model.Subscription, autotest bool, lazy bool, sortStrategy string,
|
||||
proxies ...model.Proxy,
|
||||
sub *model.Subscription, autotest bool,
|
||||
lazy bool, sortStrategy string,
|
||||
clashType model.ClashType, proxies ...model.Proxy,
|
||||
) {
|
||||
newCountryGroupNames := make([]string, 0)
|
||||
proxyTypes := model.GetSupportProxyTypes(clashType)
|
||||
|
||||
// 添加节点
|
||||
for _, proxy := range proxies {
|
||||
if !proxyTypes[proxy.Type] {
|
||||
continue
|
||||
}
|
||||
sub.Proxies = append(sub.Proxies, proxy)
|
||||
haveProxyGroup := false
|
||||
countryName := GetContryName(proxy)
|
||||
|
Loading…
Reference in New Issue
Block a user