mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-23 20:14:42 -05:00
fix
This commit is contained in:
parent
f6273947e7
commit
fe2f47865e
@ -42,16 +42,16 @@
|
||||
获取 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规则之前) |
|
||||
| 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` |
|
||||
| sort | string | 否 | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc` |
|
||||
|
||||
## 默认模板
|
||||
|
||||
|
@ -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)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
@ -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())
|
||||
}
|
||||
@ -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 {
|
||||
@ -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[:]))
|
||||
|
Loading…
Reference in New Issue
Block a user