Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nitezs committed Sep 15, 2023
1 parent f627394 commit fe2f478
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@

获取 Clash/Clash.Meta 配置链接

| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|------------------|--------|-------------------|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| sub | string | sub/proxy 至少有一项存在 | - | 订阅链接(可以输入多个,用 `,` 分隔) |
| proxy | string | sub/proxy 至少有一项存在 | - | 节点分享链接(可以输入多个,用 `,` 分隔) |
| refresh | bool || `false` | 强制刷新配置(默认缓存 5 分钟) |
| 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` | 指定国家策略组是否自动测速 |
| lazy | bool || `false` | 自动测速是否启用 lazy |
| countryGroupSort | string || `nameasc` | 国家策略组排序策略,可选值 `nameasc``namedesc``sizeasc``sizedesc` |
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|--------------|--------|-------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| sub | string | sub/proxy 至少有一项存在 | - | 订阅链接(可以输入多个,用 `,` 分隔) |
| proxy | string | sub/proxy 至少有一项存在 | - | 节点分享链接(可以输入多个,用 `,` 分隔) |
| refresh | bool || `false` | 强制刷新配置(默认缓存 5 分钟) |
| 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` | 指定国家策略组是否自动测速 |
| lazy | bool || `false` | 自动测速是否启用 lazy |
| sort | string || `nameasc` | 国家策略组排序策略,可选值 `nameasc``namedesc``sizeasc``sizedesc` |

## 默认模板

Expand Down
3 changes: 3 additions & 0 deletions api/controller/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func BuildSub(query validator.SubQuery, template string) (
var err error
var templateBytes []byte
// 加载模板
if query.Template != "" {
template = query.Template
}
_, err = url.ParseRequestURI(template)
if err != nil {
templateBytes, err = utils.LoadTemplate(template)
Expand Down
29 changes: 6 additions & 23 deletions validator/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"github.com/gin-gonic/gin"
"net/url"
"os"
"regexp"
"strings"
)
Expand Down Expand Up @@ -50,7 +51,6 @@ func ParseQuery(c *gin.Context) (SubQuery, error) {
if query.Sub != "" {
query.Subs = strings.Split(query.Sub, ",")
for i := range query.Subs {
query.Subs[i], _ = url.QueryUnescape(query.Subs[i])
if _, err := url.ParseRequestURI(query.Subs[i]); err != nil {
return SubQuery{}, errors.New("参数错误: " + err.Error())
}
Expand All @@ -60,32 +60,19 @@ func ParseQuery(c *gin.Context) (SubQuery, error) {
}
if query.Proxy != "" {
query.Proxies = strings.Split(query.Proxy, ",")
for i := range query.Proxies {
query.Proxies[i], _ = url.QueryUnescape(query.Proxies[i])
if _, err := url.ParseRequestURI(query.Proxies[i]); err != nil {
return SubQuery{}, errors.New("参数错误: " + err.Error())
}
}
} else {
query.Proxies = nil
}
if query.Template != "" {
unescape, err := url.QueryUnescape(query.Template)
uri, err := url.ParseRequestURI(query.Template)
if err != nil {
return SubQuery{}, errors.New("参数错误: " + err.Error())
if strings.Contains(query.Template, string(os.PathSeparator)) {
return SubQuery{}, err
}
}
uri, err := url.ParseRequestURI(unescape)
query.Template = uri.String()
if err != nil {
return SubQuery{}, errors.New("参数错误: " + err.Error())
}
}
if query.RuleProvider != "" {
var err error
query.RuleProvider, err = url.QueryUnescape(query.RuleProvider)
if err != nil {
return SubQuery{}, errors.New("参数错误: " + err.Error())
}
reg := regexp.MustCompile(`\[(.*?)\]`)
ruleProviders := reg.FindAllStringSubmatch(query.RuleProvider, -1)
for i := range ruleProviders {
Expand All @@ -95,15 +82,11 @@ func ParseQuery(c *gin.Context) (SubQuery, error) {
return SubQuery{}, errors.New("参数错误: ruleProvider 格式错误")
}
u := parts[1]
u, err = url.QueryUnescape(u)
if err != nil {
return SubQuery{}, errors.New("参数错误: " + err.Error())
}
uri, err := url.ParseRequestURI(u)
u = uri.String()
if err != nil {
return SubQuery{}, errors.New("参数错误: " + err.Error())
}
u = uri.String()
if len(parts) == 4 {
hash := md5.Sum([]byte(u))
parts = append(parts, hex.EncodeToString(hash[:]))
Expand Down

0 comments on commit fe2f478

Please sign in to comment.