1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 21:14:43 -05:00

fix: 修复无法加载本地模板的问题

This commit is contained in:
Nite07 2024-02-15 15:35:07 +08:00
parent 73e94ad856
commit 3616ae870a
2 changed files with 11 additions and 9 deletions

View File

@ -31,9 +31,8 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template
if query.Template != "" {
template = query.Template
}
_, err = url.ParseRequestURI(template)
if err != nil {
templateBytes, err = utils.LoadTemplate(template)
if strings.HasPrefix(template, "http") {
templateBytes, err = utils.LoadSubscription(template, query.Refresh)
if err != nil {
logger.Logger.Debug(
"load template failed", zap.String("template", template), zap.Error(err),
@ -41,7 +40,11 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template
return nil, errors.New("加载模板失败: " + err.Error())
}
} else {
templateBytes, err = utils.LoadSubscription(template, query.Refresh)
unescape, err := url.QueryUnescape(template)
if err != nil {
return nil, errors.New("加载模板失败: " + err.Error())
}
templateBytes, err = utils.LoadTemplate(unescape)
if err != nil {
logger.Logger.Debug(
"load template failed", zap.String("template", template), zap.Error(err),

View File

@ -5,7 +5,6 @@ import (
"encoding/hex"
"errors"
"net/url"
"os"
"regexp"
"strings"
@ -73,14 +72,14 @@ func ParseQuery(c *gin.Context) (SubValidator, error) {
query.Proxies = nil
}
if query.Template != "" {
if strings.HasPrefix(query.Template, "http") {
uri, err := url.ParseRequestURI(query.Template)
if err != nil {
if strings.Contains(query.Template, string(os.PathSeparator)) {
return SubValidator{}, err
}
}
query.Template = uri.String()
}
}
if query.RuleProvider != "" {
reg := regexp.MustCompile(`\[(.*?)\]`)
ruleProviders := reg.FindAllStringSubmatch(query.RuleProvider, -1)