Skip to content

Commit e5cd580

Browse files
committed
fix: v2rayN subscribe url
1 parent 1b0c288 commit e5cd580

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

controller/hysteria2.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package controller
22

33
import (
4+
"encoding/base64"
45
"fmt"
56
"github.com/gin-gonic/gin"
67
"github.com/skip2/go-qrcode"
@@ -176,7 +177,7 @@ func Hysteria2Subscribe(c *gin.Context) {
176177
clientType = constant.Clash
177178
}
178179

179-
userInfo, configYaml, err := service.Hysteria2Subscribe(conPass, clientType, host)
180+
userInfo, configStr, err := service.Hysteria2Subscribe(conPass, clientType, host)
180181
if err != nil {
181182
vo.Fail(err.Error(), c)
182183
return
@@ -186,7 +187,9 @@ func Hysteria2Subscribe(c *gin.Context) {
186187
c.Header("content-disposition", "attachment; filename=hui.yaml")
187188
c.Header("profile-update-interval", "12")
188189
c.Header("subscription-userinfo", userInfo)
190+
} else if clientType == constant.V2rayN {
191+
configStr = base64.StdEncoding.EncodeToString([]byte(configStr))
189192
}
190193

191-
c.String(200, configYaml)
194+
c.String(200, configStr)
192195
}

service/hysteria2_api.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func Hysteria2Subscribe(conPass string, clientType string, host string) (string,
123123
}
124124

125125
userInfo := ""
126-
configYaml := ""
126+
configStr := ""
127127
if clientType == constant.Shadowrocket || clientType == constant.Clash {
128128
userInfo = fmt.Sprintf("upload=%d; download=%d; total=%d; expire=%d",
129129
*account.Upload,
@@ -185,10 +185,16 @@ func Hysteria2Subscribe(conPass string, clientType string, host string) (string,
185185
if err != nil {
186186
return "", "", err
187187
}
188-
configYaml = string(clashConfigYaml)
188+
configStr = string(clashConfigYaml)
189+
} else if clientType == constant.V2rayN {
190+
hysteria2Url, err := Hysteria2Url(*account.Id, strings.Split(host, ":")[0])
191+
if err != nil {
192+
return "", "", err
193+
}
194+
configStr = hysteria2Url
189195
}
190196

191-
return userInfo, configYaml, nil
197+
return userInfo, configStr, nil
192198
}
193199

194200
func Hysteria2Url(accountId int64, hostname string) (string, error) {

0 commit comments

Comments
 (0)