mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-24 12:04:42 -05:00
fix
This commit is contained in:
parent
be9df16b61
commit
3546396e3d
@ -67,7 +67,7 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template
|
|||||||
// 解析订阅
|
// 解析订阅
|
||||||
err = yaml.Unmarshal(data, &sub)
|
err = yaml.Unmarshal(data, &sub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|http|https)://")
|
reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|vless)://")
|
||||||
if reg.Match(data) {
|
if reg.Match(data) {
|
||||||
p := utils.ParseProxy(strings.Split(string(data), "\n")...)
|
p := utils.ParseProxy(strings.Split(string(data), "\n")...)
|
||||||
proxyList = append(proxyList, p...)
|
proxyList = append(proxyList, p...)
|
||||||
|
@ -3,10 +3,14 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.uber.org/zap"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sub2clash/config"
|
"sub2clash/config"
|
||||||
|
"sub2clash/logger"
|
||||||
"sub2clash/model"
|
"sub2clash/model"
|
||||||
"sub2clash/utils"
|
"sub2clash/utils"
|
||||||
"sub2clash/utils/database"
|
"sub2clash/utils/database"
|
||||||
@ -29,7 +33,7 @@ func ShortLinkGenHandler(c *gin.Context) {
|
|||||||
var item model.ShortLink
|
var item model.ShortLink
|
||||||
result := database.FindShortLinkByUrl(params.Url, &item)
|
result := database.FindShortLinkByUrl(params.Url, &item)
|
||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
if params.Password != "" && item.Password != params.Password {
|
if item.Password != params.Password {
|
||||||
item.Password = params.Password
|
item.Password = params.Password
|
||||||
database.SaveShortLink(&item)
|
database.SaveShortLink(&item)
|
||||||
c.String(200, item.Hash+"?password="+params.Password)
|
c.String(200, item.Hash+"?password="+params.Password)
|
||||||
@ -88,6 +92,17 @@ func ShortLinkGetHandler(c *gin.Context) {
|
|||||||
// 更新最后访问时间
|
// 更新最后访问时间
|
||||||
shortLink.LastRequestTime = time.Now().Unix()
|
shortLink.LastRequestTime = time.Now().Unix()
|
||||||
database.SaveShortLink(&shortLink)
|
database.SaveShortLink(&shortLink)
|
||||||
uri := config.Default.BasePath + shortLink.Url
|
get, err := utils.Get("http://localhost:" + strconv.Itoa(config.Default.Port) + "/" + shortLink.Url)
|
||||||
c.Redirect(http.StatusTemporaryRedirect, uri)
|
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))
|
||||||
}
|
}
|
||||||
|
@ -15,39 +15,83 @@ proxy-groups:
|
|||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
- <all>
|
- <all>
|
||||||
- name: 微软服务
|
- name: 游戏平台(中国)
|
||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
- <countries>
|
|
||||||
- 节点选择
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
- 手动切换
|
- 手动切换
|
||||||
- DIRECT
|
- DIRECT
|
||||||
- name: 游戏平台
|
- name: 游戏平台(全球)
|
||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
- <countries>
|
|
||||||
- 节点选择
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
- 手动切换
|
- 手动切换
|
||||||
- DIRECT
|
- DIRECT
|
||||||
- name: 巴哈姆特
|
- name: 巴哈姆特
|
||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
- <countries>
|
|
||||||
- 节点选择
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
- 手动切换
|
- 手动切换
|
||||||
- DIRECT
|
- DIRECT
|
||||||
- name: 哔哩哔哩
|
- name: 哔哩哔哩
|
||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
- <countries>
|
|
||||||
- 节点选择
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
- 手动切换
|
- 手动切换
|
||||||
- DIRECT
|
- DIRECT
|
||||||
- name: 全球直连
|
- name: Telegram
|
||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
- DIRECT
|
|
||||||
- 节点选择
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
|
- 手动切换
|
||||||
|
- DIRECT
|
||||||
|
- name: OpenAI
|
||||||
|
type: select
|
||||||
|
proxies:
|
||||||
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
|
- 手动切换
|
||||||
|
- DIRECT
|
||||||
|
- name: Youtube
|
||||||
|
type: select
|
||||||
|
proxies:
|
||||||
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
|
- 手动切换
|
||||||
|
- DIRECT
|
||||||
|
- name: Microsoft
|
||||||
|
type: select
|
||||||
|
proxies:
|
||||||
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
|
- 手动切换
|
||||||
|
- DIRECT
|
||||||
|
- name: Onedrive
|
||||||
|
type: select
|
||||||
|
proxies:
|
||||||
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
|
- 手动切换
|
||||||
|
- DIRECT
|
||||||
|
- name: Apple
|
||||||
|
type: select
|
||||||
|
proxies:
|
||||||
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
|
- 手动切换
|
||||||
|
- DIRECT
|
||||||
|
- name: Netflix
|
||||||
|
type: select
|
||||||
|
proxies:
|
||||||
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
|
- 手动切换
|
||||||
|
- DIRECT
|
||||||
- name: 广告拦截
|
- name: 广告拦截
|
||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
@ -56,19 +100,26 @@ proxy-groups:
|
|||||||
- name: 漏网之鱼
|
- name: 漏网之鱼
|
||||||
type: select
|
type: select
|
||||||
proxies:
|
proxies:
|
||||||
- <countries>
|
|
||||||
- 节点选择
|
- 节点选择
|
||||||
|
- <countries>
|
||||||
- 手动切换
|
- 手动切换
|
||||||
- DIRECT
|
- DIRECT
|
||||||
rules:
|
rules:
|
||||||
- GEOSITE,private,全球直连,no-resolve
|
- GEOSITE,private,DIRECT,no-resolve
|
||||||
- GEOIP,private,全球直连
|
- GEOIP,private,DIRECT
|
||||||
- GEOSITE,category-ads-all,广告拦截
|
- 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,bilibili,哔哩哔哩
|
||||||
- GEOSITE,bahamut,巴哈姆特
|
- GEOSITE,bahamut,巴哈姆特
|
||||||
- GEOSITE,category-games,游戏平台
|
- GEOSITE,category-games@cn,游戏平台(中国)
|
||||||
|
- GEOSITE,category-games,游戏平台(全球)
|
||||||
- GEOSITE,geolocation-!cn,节点选择
|
- GEOSITE,geolocation-!cn,节点选择
|
||||||
- GEOSITE,CN,全球直连
|
- GEOSITE,CN,DIRECT
|
||||||
- GEOIP,CN,全球直连
|
- GEOIP,CN,DIRECT
|
||||||
- MATCH,漏网之鱼
|
- MATCH,漏网之鱼
|
||||||
|
@ -13,17 +13,13 @@ func Get(url string) (resp *http.Response, err error) {
|
|||||||
retryDelay := time.Second // 延迟1秒再重试
|
retryDelay := time.Second // 延迟1秒再重试
|
||||||
for haveTried < retryTimes {
|
for haveTried < retryTimes {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
client.Timeout = time.Second * 10
|
//client.Timeout = time.Second * 10
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
haveTried++
|
haveTried++
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
continue
|
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)
|
get, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
haveTried++
|
haveTried++
|
||||||
|
Loading…
Reference in New Issue
Block a user