diff --git a/api/controller/default.go b/api/controller/default.go index 53ae47e..20bca76 100644 --- a/api/controller/default.go +++ b/api/controller/default.go @@ -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), diff --git a/validator/sub.go b/validator/sub.go index 4ed6a9e..ea9dd8d 100644 --- a/validator/sub.go +++ b/validator/sub.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "errors" "net/url" - "os" "regexp" "strings" @@ -73,13 +72,13 @@ func ParseQuery(c *gin.Context) (SubValidator, error) { query.Proxies = nil } if query.Template != "" { - uri, err := url.ParseRequestURI(query.Template) - if err != nil { - if strings.Contains(query.Template, string(os.PathSeparator)) { + if strings.HasPrefix(query.Template, "http") { + uri, err := url.ParseRequestURI(query.Template) + if err != nil { return SubValidator{}, err } + query.Template = uri.String() } - query.Template = uri.String() } if query.RuleProvider != "" { reg := regexp.MustCompile(`\[(.*?)\]`)