From 3546396e3d60f2c7c3755b8c9626d4fc9b0ea01b Mon Sep 17 00:00:00 2001 From: nitezs Date: Sat, 23 Sep 2023 08:48:45 +0800 Subject: [PATCH] fix --- api/controller/default.go | 2 +- api/controller/short_link.go | 21 ++++++++-- templates/template_meta.yaml | 81 +++++++++++++++++++++++++++++------- utils/get.go | 6 +-- 4 files changed, 86 insertions(+), 24 deletions(-) diff --git a/api/controller/default.go b/api/controller/default.go index 174dccf..e0eed50 100644 --- a/api/controller/default.go +++ b/api/controller/default.go @@ -67,7 +67,7 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template // 解析订阅 err = yaml.Unmarshal(data, &sub) if err != nil { - reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|http|https)://") + reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|vless)://") if reg.Match(data) { p := utils.ParseProxy(strings.Split(string(data), "\n")...) proxyList = append(proxyList, p...) diff --git a/api/controller/short_link.go b/api/controller/short_link.go index 4e9101e..9c39619 100644 --- a/api/controller/short_link.go +++ b/api/controller/short_link.go @@ -3,10 +3,14 @@ package controller import ( "errors" "github.com/gin-gonic/gin" + "go.uber.org/zap" "gorm.io/gorm" + "io" "net/http" + "strconv" "strings" "sub2clash/config" + "sub2clash/logger" "sub2clash/model" "sub2clash/utils" "sub2clash/utils/database" @@ -29,7 +33,7 @@ func ShortLinkGenHandler(c *gin.Context) { var item model.ShortLink result := database.FindShortLinkByUrl(params.Url, &item) if result.Error == nil { - if params.Password != "" && item.Password != params.Password { + if item.Password != params.Password { item.Password = params.Password database.SaveShortLink(&item) c.String(200, item.Hash+"?password="+params.Password) @@ -88,6 +92,17 @@ func ShortLinkGetHandler(c *gin.Context) { // 更新最后访问时间 shortLink.LastRequestTime = time.Now().Unix() database.SaveShortLink(&shortLink) - uri := config.Default.BasePath + shortLink.Url - c.Redirect(http.StatusTemporaryRedirect, uri) + get, err := utils.Get("http://localhost:" + strconv.Itoa(config.Default.Port) + "/" + shortLink.Url) + if err != nil { + logger.Logger.Debug("get short link data failed", zap.Error(err)) + c.String(500, "请求错误: "+err.Error()) + return + } + all, err := io.ReadAll(get.Body) + if err != nil { + logger.Logger.Debug("read short link data failed", zap.Error(err)) + c.String(500, "读取错误: "+err.Error()) + return + } + c.String(http.StatusOK, string(all)) } diff --git a/templates/template_meta.yaml b/templates/template_meta.yaml index 0711087..8885bf4 100644 --- a/templates/template_meta.yaml +++ b/templates/template_meta.yaml @@ -15,39 +15,83 @@ proxy-groups: type: select proxies: - - - name: 微软服务 + - name: 游戏平台(中国) type: select proxies: - - - 节点选择 + - - 手动切换 - DIRECT - - name: 游戏平台 + - name: 游戏平台(全球) type: select proxies: - - - 节点选择 + - - 手动切换 - DIRECT - name: 巴哈姆特 type: select proxies: - - - 节点选择 + - - 手动切换 - DIRECT - name: 哔哩哔哩 type: select proxies: - - - 节点选择 + - - 手动切换 - DIRECT - - name: 全球直连 + - name: Telegram type: select proxies: - - DIRECT - 节点选择 + - + - 手动切换 + - DIRECT + - name: OpenAI + type: select + proxies: + - 节点选择 + - + - 手动切换 + - DIRECT + - name: Youtube + type: select + proxies: + - 节点选择 + - + - 手动切换 + - DIRECT + - name: Microsoft + type: select + proxies: + - 节点选择 + - + - 手动切换 + - DIRECT + - name: Onedrive + type: select + proxies: + - 节点选择 + - + - 手动切换 + - DIRECT + - name: Apple + type: select + proxies: + - 节点选择 + - + - 手动切换 + - DIRECT + - name: Netflix + type: select + proxies: + - 节点选择 + - + - 手动切换 + - DIRECT - name: 广告拦截 type: select proxies: @@ -56,19 +100,26 @@ proxy-groups: - name: 漏网之鱼 type: select proxies: - - - 节点选择 + - - 手动切换 - DIRECT rules: - - GEOSITE,private,全球直连,no-resolve - - GEOIP,private,全球直连 + - GEOSITE,private,DIRECT,no-resolve + - GEOIP,private,DIRECT - GEOSITE,category-ads-all,广告拦截 - - GEOSITE,microsoft,微软服务 + - GEOSITE,microsoft,Microsoft + - GEOSITE,apple,Apple + - GEOSITE,netflix,Netflix + - GEOSITE,onedrive,Onedrive + - GEOSITE,youtube,Youtube + - GEOSITE,telegram,Telegram + - GEOSITE,openai,OpenAI - GEOSITE,bilibili,哔哩哔哩 - GEOSITE,bahamut,巴哈姆特 - - GEOSITE,category-games,游戏平台 + - GEOSITE,category-games@cn,游戏平台(中国) + - GEOSITE,category-games,游戏平台(全球) - GEOSITE,geolocation-!cn,节点选择 - - GEOSITE,CN,全球直连 - - GEOIP,CN,全球直连 + - GEOSITE,CN,DIRECT + - GEOIP,CN,DIRECT - MATCH,漏网之鱼 diff --git a/utils/get.go b/utils/get.go index bcf8765..a7fbc96 100644 --- a/utils/get.go +++ b/utils/get.go @@ -13,17 +13,13 @@ func Get(url string) (resp *http.Response, err error) { retryDelay := time.Second // 延迟1秒再重试 for haveTried < retryTimes { client := &http.Client{} - client.Timeout = time.Second * 10 + //client.Timeout = time.Second * 10 req, err := http.NewRequest("GET", url, nil) if err != nil { haveTried++ time.Sleep(retryDelay) continue } - req.Header.Set( - "User-Agent", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", - ) get, err := client.Do(req) if err != nil { haveTried++