From d38d5bcb702e803f646e82e084f3ad092c72ae97 Mon Sep 17 00:00:00 2001 From: nitezs Date: Sat, 16 Sep 2023 21:46:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Web=20UI=20update:=20=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?Rule-Provider=E6=98=AF=E5=90=A6=E6=9C=89=E9=87=8D=E5=90=8D=20mo?= =?UTF-8?q?dify:=20=E4=BF=AE=E6=94=B9meta=E9=BB=98=E8=AE=A4=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=20modify:=20=E6=A0=B9=E6=8D=AEClash=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- api/route.go | 12 ++ api/templates/index.html | 279 +++++++++++++++++++++++++++++++++++ templates/template_meta.yaml | 14 +- utils/template.go | 2 +- validator/sub.go | 10 +- 6 files changed, 313 insertions(+), 8 deletions(-) create mode 100644 api/templates/index.html diff --git a/README.md b/README.md index 836a407..fbc9882 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ | template | string | 否 | - | 外部模板链接或内部模板名称 | | ruleProvider | string | 否 | - | 格式 `[Behavior,Url,Group,Prepend,Name],[Behavior,Url,Group,Prepend,Name]...`,其中 `Group` 是该规则集所走的策略组名,`Prepend` 为 bool 类型,如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部(会调整到MATCH规则之前) | | rule | string | 否 | - | 格式 `[Rule,Prepend],[Rule,Prepend]...`,其中 `Prepend` 为 bool 类型,如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部(会调整到MATCH规则之前) | -| autoTest | bool | 否 | `false` | 指定国家策略组是否自动测速 | +| autoTest | bool | 否 | `false` | 国家策略组是否自动测速 | | lazy | bool | 否 | `false` | 自动测速是否启用 lazy | | sort | string | 否 | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc` | @@ -64,4 +64,4 @@ ## TODO -- [ ] 可视化面板 \ No newline at end of file +- [x] 可视化面板 \ No newline at end of file diff --git a/api/route.go b/api/route.go index 4feb5e9..e56cc39 100644 --- a/api/route.go +++ b/api/route.go @@ -1,13 +1,25 @@ package api import ( + "embed" "github.com/gin-gonic/gin" + "html/template" "sub2clash/api/controller" "sub2clash/middleware" ) +//go:embed templates/* +var templates embed.FS + func SetRoute(r *gin.Engine) { r.Use(middleware.ZapLogger()) + // 使用内嵌的模板文件 + r.SetHTMLTemplate(template.Must(template.New("").ParseFS(templates, "templates/*"))) + r.GET( + "/", func(c *gin.Context) { + c.HTML(200, "index.html", nil) + }, + ) r.GET( "/clash", func(c *gin.Context) { controller.SubmodHandler(c) diff --git a/api/templates/index.html b/api/templates/index.html new file mode 100644 index 0000000..2e75aa0 --- /dev/null +++ b/api/templates/index.html @@ -0,0 +1,279 @@ + + + + + + + sub2clash + + + + + + + + + + + + +
+
+

sub2clash

+ 通用订阅链接转 Clash(Meta) 配置工具 使用文档 +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + +
+ + +
+ +
+ + +
+
+ + + + +
+ + + + + diff --git a/templates/template_meta.yaml b/templates/template_meta.yaml index ea0bcf0..ec264c5 100644 --- a/templates/template_meta.yaml +++ b/templates/template_meta.yaml @@ -13,6 +13,12 @@ proxy-groups: - name: 手动切换 type: select proxies: + - name: 微软服务 + type: select + proxies: + - 节点选择 + - 手动切换 + - DIRECT - name: 游戏平台 type: select proxies: @@ -48,14 +54,14 @@ proxy-groups: - 手动切换 - DIRECT rules: - - GEOSITE,private,全球直连 + - GEOSITE,private,全球直连,no-resolve - GEOIP,private,全球直连 - GEOSITE,category-ads-all,广告拦截 - - GEOSITE,CN,全球直连 - - GEOIP,CN,全球直连 - - GEOSITE,biliintl,哔哩哔哩 + - GEOSITE,microsoft,微软服务 - GEOSITE,bilibili,哔哩哔哩 - GEOSITE,bahamut,巴哈姆特 - GEOSITE,category-games,游戏平台 - GEOSITE,geolocation-!cn,节点选择 + - GEOSITE,CN,全球直连 + - GEOIP,CN,全球直连 - MATCH,漏网之鱼 \ No newline at end of file diff --git a/utils/template.go b/utils/template.go index cd90a45..781a099 100644 --- a/utils/template.go +++ b/utils/template.go @@ -8,7 +8,7 @@ import ( ) // LoadTemplate 加载模板 -// template 模板文件名 +// templates 模板文件名 func LoadTemplate(template string) ([]byte, error) { tPath := filepath.Join("templates", template) if _, err := os.Stat(tPath); err == nil { diff --git a/validator/sub.go b/validator/sub.go index bd2b649..4db8340 100644 --- a/validator/sub.go +++ b/validator/sub.go @@ -17,7 +17,7 @@ type SubQuery struct { Proxy string `form:"proxy" binding:""` Proxies []string `form:"-" binding:""` Refresh bool `form:"refresh,default=false" binding:""` - Template string `form:"template" binding:""` + Template string `form:"templates" binding:""` RuleProvider string `form:"ruleProvider" binding:""` RuleProviders []RuleProviderStruct `form:"-" binding:""` Rule string `form:"rule" binding:""` @@ -101,6 +101,14 @@ func ParseQuery(c *gin.Context) (SubQuery, error) { }, ) } + // 校验 Rule-Provider 是否有重名 + names := make(map[string]bool) + for _, ruleProvider := range query.RuleProviders { + if _, ok := names[ruleProvider.Name]; ok { + return SubQuery{}, errors.New("参数错误: Rule-Provider 名称重复") + } + names[ruleProvider.Name] = true + } } else { query.RuleProviders = nil }