Skip to content

Commit

Permalink
update: 校验Rule-Provider是否有重名
Browse files Browse the repository at this point in the history
modify: 修改meta默认模板
modify: 调整 WebUI
  • Loading branch information
nitezs committed Sep 17, 2023
1 parent ba6aa26 commit 63b6110
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

Expand Down
24 changes: 19 additions & 5 deletions api/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@
.container {
max-width: 800px;
}

.btn-xs {
padding: 2px 2px; /* 调整内边距以减小按钮大小 */
font-size: 10px; /* 设置字体大小 */
line-height: 1.2; /* 调整行高 */
border-radius: 3px; /* 可选的边框半径调整 */
height: 25px;
width: 25px;
}
</style>
</head>

<body class="bg-light">

<div class="container mt-5">
<h2 class="mb-4">sub2clash</h2>
<div class="mb-4">
<h2>sub2clash</h2>
<span class="text-muted fst-italic">通用订阅链接转 Clash(Meta) 配置工具 <a
href="https://github.com/nitezs/sub2clash#clash-meta" target="_blank">使用文档</a></span>
</div>

<form id="apiForm">

<!-- API Endpoint -->
<div class="form-group mb-3">
<label for="endpoint">API 端点:</label>
<label for="endpoint">客户的类型:</label>
<select class="form-control" id="endpoint" name="endpoint">
<option value="clash">Clash</option>
<option value="meta">Meta</option>
<option value="meta">Clash.Meta</option>
</select>
</div>

Expand Down Expand Up @@ -66,13 +80,13 @@ <h2 class="mb-4">sub2clash</h2>
<!-- Rule Provider -->
<div class="form-group mb-3" id="ruleProviderGroup">
<label>Rule Provider:</label>
<button type="button" class="btn btn-primary mb-2" onclick="addRuleProvider()">+</button>
<button type="button" class="btn btn-primary mb-1 btn-xs" onclick="addRuleProvider()">+</button>
</div>

<!-- Rule -->
<div class="form-group mb-3" id="ruleGroup">
<label>规则:</label>
<button type="button" class="btn btn-primary mb-2" onclick="addRule()">+</button>
<button type="button" class="btn btn-primary mb-1 btn-xs" onclick="addRule()">+</button>
</div>

<!-- Auto Test -->
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,3 @@ func main() {
return
}
}

// TODO: 校验 Rule-Provider 是否有重名
14 changes: 10 additions & 4 deletions templates/template_meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ proxy-groups:
- name: 手动切换
type: select
proxies:
- name: 微软服务
type: select
proxies:
- 节点选择
- 手动切换
- DIRECT
- name: 游戏平台
type: select
proxies:
Expand Down Expand Up @@ -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,漏网之鱼
8 changes: 8 additions & 0 deletions validator/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 63b6110

Please sign in to comment.