Skip to content

Commit

Permalink
fix: 修复无法加载本地模板的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nitezs committed Feb 15, 2024
1 parent 73e94ad commit 3616ae8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 7 additions & 4 deletions api/controller/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ 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),
)
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),
Expand Down
9 changes: 4 additions & 5 deletions validator/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"errors"
"net/url"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -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(`\[(.*?)\]`)
Expand Down

0 comments on commit 3616ae8

Please sign in to comment.