1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-24 11:44:42 -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 != "" { if query.Template != "" {
template = query.Template template = query.Template
} }
_, err = url.ParseRequestURI(template) if strings.HasPrefix(template, "http") {
if err != nil { templateBytes, err = utils.LoadSubscription(template, query.Refresh)
templateBytes, err = utils.LoadTemplate(template)
if err != nil { if err != nil {
logger.Logger.Debug( logger.Logger.Debug(
"load template failed", zap.String("template", template), zap.Error(err), "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()) return nil, errors.New("加载模板失败: " + err.Error())
} }
} else { } 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 { if err != nil {
logger.Logger.Debug( logger.Logger.Debug(
"load template failed", zap.String("template", template), zap.Error(err), "load template failed", zap.String("template", template), zap.Error(err),

View File

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