add noneed country filter
This commit is contained in:
@@ -69,8 +69,9 @@ func setupRouter() {
|
||||
router.GET("/clash/proxies", func(c *gin.Context) {
|
||||
proxyTypes := c.DefaultQuery("type", "")
|
||||
proxyCountry := c.DefaultQuery("c", "")
|
||||
proxyNotCountry := c.DefaultQuery("nc", "")
|
||||
text := ""
|
||||
if proxyTypes == "" && proxyCountry == "" {
|
||||
if proxyTypes == "" && proxyCountry == "" && proxyNotCountry == "" {
|
||||
text = cache.GetString("clashproxies")
|
||||
if text == "" {
|
||||
proxies := cache.GetProxies("proxies")
|
||||
@@ -80,11 +81,21 @@ func setupRouter() {
|
||||
}
|
||||
} else if proxyTypes == "all" {
|
||||
proxies := cache.GetProxies("allproxies")
|
||||
clash := provider.Clash{Proxies: proxies, Types: proxyTypes, Country: proxyCountry}
|
||||
clash := provider.Clash{
|
||||
Proxies: proxies,
|
||||
Types: proxyTypes,
|
||||
Country: proxyCountry,
|
||||
NotCountry: proxyNotCountry,
|
||||
}
|
||||
text = clash.Provide()
|
||||
} else {
|
||||
proxies := cache.GetProxies("proxies")
|
||||
clash := provider.Clash{Proxies: proxies, Types: proxyTypes, Country: proxyCountry}
|
||||
clash := provider.Clash{
|
||||
Proxies: proxies,
|
||||
Types: proxyTypes,
|
||||
Country: proxyCountry,
|
||||
NotCountry: proxyNotCountry,
|
||||
}
|
||||
text = clash.Provide()
|
||||
}
|
||||
c.String(200, text)
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
<p>Clash proxy-provider(Shadowrocket添加订阅方式可用):<a href="https://{{ .domain }}/clash/proxies">https://{{ .domain }}/clash/proxies</a></p>
|
||||
<br>
|
||||
<p>筛选代理类型(此种方式你只能自己维护配置文件):https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess</p>
|
||||
<p>筛选国家(此种方式你只能自己维护配置文件):https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess&c=HK,TW,US</p>
|
||||
<p>筛选国家:https://{{ .domain }}/clash/proxies?c=HK,TW,US&nc=JP (c为需要的国家,nc为不需要的国家)</p>
|
||||
<p>所有节点的Provider(不是都可以用):<a href="https://{{ .domain }}/clash/proxies?type=all">https://{{ .domain }}/clash/proxies?type=all</a></p>
|
||||
<br>
|
||||
<p>抓取程序已开源:<a href="https://github.com/zu1k/proxypool">https://github.com/zu1k/proxypool</a></p>
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
<p>Clash proxy-provider(Shadowrocket添加订阅方式可用):<a href="https://{{ .domain }}/clash/proxies">https://{{ .domain }}/clash/proxies</a>
|
||||
</p>
|
||||
<p>筛选代理类型:https://{{ .domain }}/clash/proxies?type=ss,ssr,vmess</p>
|
||||
<p>筛选国家:https://{{ .domain }}/clash/proxies?c=HK,TW,US</p>
|
||||
<p>筛选国家:https://{{ .domain }}/clash/proxies?c=HK,TW,US&nc=JP (c为需要的国家,nc为不需要的国家)</p>
|
||||
<br>
|
||||
<h4><a href="/surge">Surge</a></h4>
|
||||
<p>Surge配置文件:https://{{ .domain }}/surge/config <a
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
)
|
||||
|
||||
type Clash struct {
|
||||
Proxies proxy.ProxyList `yaml:"proxies"`
|
||||
Types string `yaml:"type"`
|
||||
Country string `yaml:"country"`
|
||||
Proxies proxy.ProxyList `yaml:"proxies"`
|
||||
Types string `yaml:"type"`
|
||||
Country string `yaml:"country"`
|
||||
NotCountry string `yaml:"not_country"`
|
||||
}
|
||||
|
||||
func (c Clash) CleanProxies() (proxies proxy.ProxyList) {
|
||||
@@ -26,44 +27,63 @@ func (c Clash) Provide() string {
|
||||
var resultBuilder strings.Builder
|
||||
resultBuilder.WriteString("proxies:\n")
|
||||
|
||||
noNeedFilterType := false
|
||||
noNeedFilterCountry := false
|
||||
needFilterType := true
|
||||
needFilterCountry := true
|
||||
needFilterNotCountry := true
|
||||
if c.Types == "" || c.Types == "all" {
|
||||
noNeedFilterType = true
|
||||
needFilterType = false
|
||||
}
|
||||
if c.Country == "" || c.Country == "all" {
|
||||
noNeedFilterCountry = true
|
||||
needFilterCountry = false
|
||||
}
|
||||
if c.NotCountry == "" {
|
||||
needFilterNotCountry = false
|
||||
}
|
||||
types := strings.Split(c.Types, ",")
|
||||
countries := strings.Split(c.Country, ",")
|
||||
notCountries := strings.Split(c.NotCountry, ",")
|
||||
|
||||
for _, p := range c.Proxies {
|
||||
if !checkClashSupport(p) {
|
||||
continue
|
||||
}
|
||||
|
||||
typeOk := false
|
||||
countryOk := false
|
||||
if !noNeedFilterType {
|
||||
if needFilterType {
|
||||
typeOk := false
|
||||
for _, t := range types {
|
||||
if p.TypeName() == t {
|
||||
typeOk = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !typeOk {
|
||||
goto exclude
|
||||
}
|
||||
}
|
||||
if !noNeedFilterCountry {
|
||||
|
||||
if needFilterNotCountry {
|
||||
for _, c := range notCountries {
|
||||
if strings.Contains(p.BaseInfo().Name, c) {
|
||||
goto exclude
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if needFilterCountry {
|
||||
countryOk := false
|
||||
for _, c := range countries {
|
||||
if strings.Contains(p.BaseInfo().Name, c) {
|
||||
countryOk = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !countryOk {
|
||||
goto exclude
|
||||
}
|
||||
}
|
||||
|
||||
if (noNeedFilterType || typeOk) && (noNeedFilterCountry || countryOk) {
|
||||
resultBuilder.WriteString(p.ToClash() + "\n")
|
||||
}
|
||||
resultBuilder.WriteString(p.ToClash() + "\n")
|
||||
exclude:
|
||||
}
|
||||
|
||||
return resultBuilder.String()
|
||||
|
||||
Reference in New Issue
Block a user