From 94a320a682f7733b2ebda468e7219588a9a58afc Mon Sep 17 00:00:00 2001 From: nite07 Date: Sun, 10 Mar 2024 13:26:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=B8=8D=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E5=9B=BD=E5=AE=B6=E7=AD=96=E7=95=A5=E7=BB=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/default.go | 14 +- api/static/index.html | 404 ++++++++++++++------------------------ api/static/index.js | 3 + utils/proxy.go | 6 - utils/sub.go | 3 - utils/template.go | 3 - validator/sub.go | 37 ++-- 7 files changed, 175 insertions(+), 295 deletions(-) diff --git a/api/controller/default.go b/api/controller/default.go index 4ff52a4..55a9d4e 100644 --- a/api/controller/default.go +++ b/api/controller/default.go @@ -74,7 +74,7 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template } // 解析订阅 err = yaml.Unmarshal(data, &sub) - newProxies := make([]model.Proxy, 0) + var newProxies []model.Proxy if err != nil { reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|vless|hysteria)://") if reg.Match(data) { @@ -157,10 +157,6 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template for i := range proxyList { // 重命名匹配到的节点 for j, v := range replaceRegs { - if err != nil { - logger.Logger.Debug("replace regexp compile failed", zap.Error(err)) - return nil, errors.New("replaceName 参数非法: " + err.Error()) - } if v.MatchString(proxyList[i].Name) { proxyList[i].Name = v.ReplaceAllString( proxyList[i].Name, query.ReplaceTo[j], @@ -200,7 +196,7 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template sort.Sort(model.ProxyGroupsSortByName(t.ProxyGroups)) } // 合并新节点和模板 - MergeSubAndTemplate(temp, t) + MergeSubAndTemplate(temp, t, query.IgnoreCountryGrooup) // 处理自定义规则 for _, v := range query.Rules { if v.Prepend { @@ -233,7 +229,7 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template return temp, nil } -func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription) { +func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg bool) { // 只合并节点、策略组 // 统计所有国家策略组名称 var countryGroupNames []string @@ -284,5 +280,7 @@ func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription) { } temp.ProxyGroups[i].Proxies = newProxies } - temp.ProxyGroups = append(temp.ProxyGroups, sub.ProxyGroups...) + if !igcg { + temp.ProxyGroups = append(temp.ProxyGroups, sub.ProxyGroups...) + } } diff --git a/api/static/index.html b/api/static/index.html index 0bc756c..367fd4d 100644 --- a/api/static/index.html +++ b/api/static/index.html @@ -1,22 +1,16 @@ + - - + + sub2clash - + - + @@ -26,260 +20,156 @@ } .btn-xs { - padding: 2px 2px; /* 调整内边距以减小按钮大小 */ - font-size: 10px; /* 设置字体大小 */ - line-height: 1.2; /* 调整行高 */ - border-radius: 3px; /* 可选的边框半径调整 */ + padding: 2px 2px; + /* 调整内边距以减小按钮大小 */ + font-size: 10px; + /* 设置字体大小 */ + line-height: 1.2; + /* 调整行高 */ + border-radius: 3px; + /* 可选的边框半径调整 */ height: 25px; width: 25px; } + -
-
-

sub2clash

- 通用订阅链接转 Clash(Meta) 配置工具 - 使用文档
注意:本程序非纯前端程序,输入的订阅将被后端缓存,请确保您信任当前站点 -
+
+
+

sub2clash

+ 通用订阅链接转 Clash(Meta) 配置工具 + 使用文档
注意:本程序非纯前端程序,输入的订阅将被后端缓存,请确保您信任当前站点 +
- -
- -
- - +
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
-
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- -
- - - -
-
- - - - + +
+ +
+ + + +
+
+ + + + +
+ +
+

+ Powered by + sub2clash +

+

Version {{.Version}}

+
- - -
- + + \ No newline at end of file diff --git a/api/static/index.js b/api/static/index.js index 388205c..5e54520 100644 --- a/api/static/index.js +++ b/api/static/index.js @@ -6,6 +6,7 @@ function clearExistingValues() { document.getElementById("refresh").checked = false; document.getElementById("autoTest").checked = false; document.getElementById("lazy").checked = false; + document.getElementById("igcg").checked = false; document.getElementById("template").value = ""; document.getElementById("sort").value = "nameasc"; document.getElementById("remove").value = ""; @@ -74,6 +75,8 @@ function generateURI() { queryParams.push(`lazy=${lazy ? "true" : "false"}`); const nodeList = document.getElementById("nodeList").checked; queryParams.push(`nodeList=${nodeList ? "true" : "false"}`); + const igcg = document.getElementById("igcg").checked; + queryParams.push(`ignoreCountryGroup=${igcg ? "true" : "false"}`); // 获取模板链接或名称(如果存在) const template = document.getElementById("template").value; diff --git a/utils/proxy.go b/utils/proxy.go index 16ed5ff..e483f10 100644 --- a/utils/proxy.go +++ b/utils/proxy.go @@ -65,17 +65,11 @@ func AddProxy( countryName := GetContryName(proxy.Name) for i := range sub.ProxyGroups { group := &sub.ProxyGroups[i] - if group.Name == countryName { group.Proxies = append(group.Proxies, proxy.Name) group.Size++ haveProxyGroup = true } - - if group.Name == "手动切换" { - group.Proxies = append(group.Proxies, proxy.Name) - group.Size++ - } } if !haveProxyGroup { var newGroup model.ProxyGroup diff --git a/utils/sub.go b/utils/sub.go index d7442b1..bad44dd 100644 --- a/utils/sub.go +++ b/utils/sub.go @@ -81,8 +81,5 @@ func FetchSubscriptionFromAPI(url string) ([]byte, error) { if err != nil { return nil, fmt.Errorf("failed to write to sub.yaml: %w", err) } - if err != nil { - return nil, fmt.Errorf("failed to unmarshal yaml: %w", err) - } return data, nil } diff --git a/utils/template.go b/utils/template.go index 45bf68a..6772a46 100644 --- a/utils/template.go +++ b/utils/template.go @@ -25,9 +25,6 @@ func LoadTemplate(template string) ([]byte, error) { if err != nil { return nil, err } - if err != nil { - return nil, err - } return result, nil } return nil, errors.New("模板文件不存在") diff --git a/validator/sub.go b/validator/sub.go index ea9dd8d..1557257 100644 --- a/validator/sub.go +++ b/validator/sub.go @@ -12,24 +12,25 @@ import ( ) type SubValidator struct { - Sub string `form:"sub" binding:""` - Subs []string `form:"-" binding:""` - Proxy string `form:"proxy" binding:""` - Proxies []string `form:"-" binding:""` - Refresh bool `form:"refresh,default=false" binding:""` - Template string `form:"template" binding:""` - RuleProvider string `form:"ruleProvider" binding:""` - RuleProviders []RuleProviderStruct `form:"-" binding:""` - Rule string `form:"rule" binding:""` - Rules []RuleStruct `form:"-" binding:""` - AutoTest bool `form:"autoTest,default=false" binding:""` - Lazy bool `form:"lazy,default=false" binding:""` - Sort string `form:"sort" binding:""` - Remove string `form:"remove" binding:""` - Replace string `form:"replace" binding:""` - ReplaceKeys []string `form:"-" binding:""` - ReplaceTo []string `form:"-" binding:""` - NodeListMode bool `form:"nodeList,default=false" binding:""` + Sub string `form:"sub" binding:""` + Subs []string `form:"-" binding:""` + Proxy string `form:"proxy" binding:""` + Proxies []string `form:"-" binding:""` + Refresh bool `form:"refresh,default=false" binding:""` + Template string `form:"template" binding:""` + RuleProvider string `form:"ruleProvider" binding:""` + RuleProviders []RuleProviderStruct `form:"-" binding:""` + Rule string `form:"rule" binding:""` + Rules []RuleStruct `form:"-" binding:""` + AutoTest bool `form:"autoTest,default=false" binding:""` + Lazy bool `form:"lazy,default=false" binding:""` + Sort string `form:"sort" binding:""` + Remove string `form:"remove" binding:""` + Replace string `form:"replace" binding:""` + ReplaceKeys []string `form:"-" binding:""` + ReplaceTo []string `form:"-" binding:""` + NodeListMode bool `form:"nodeList,default=false" binding:""` + IgnoreCountryGrooup bool `form:"ignoreCountryGroup,default=false" binding:""` } type RuleProviderStruct struct {