Skip to content

Commit

Permalink
fix: v2rayN subscribe url
Browse files Browse the repository at this point in the history
  • Loading branch information
jonssonyan committed Dec 10, 2024
1 parent 1b0c288 commit e5cd580
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions controller/hysteria2.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"encoding/base64"
"fmt"
"github.com/gin-gonic/gin"
"github.com/skip2/go-qrcode"
Expand Down Expand Up @@ -176,7 +177,7 @@ func Hysteria2Subscribe(c *gin.Context) {
clientType = constant.Clash
}

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

c.String(200, configYaml)
c.String(200, configStr)
}
12 changes: 9 additions & 3 deletions service/hysteria2_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func Hysteria2Subscribe(conPass string, clientType string, host string) (string,
}

userInfo := ""
configYaml := ""
configStr := ""
if clientType == constant.Shadowrocket || clientType == constant.Clash {
userInfo = fmt.Sprintf("upload=%d; download=%d; total=%d; expire=%d",
*account.Upload,
Expand Down Expand Up @@ -185,10 +185,16 @@ func Hysteria2Subscribe(conPass string, clientType string, host string) (string,
if err != nil {
return "", "", err
}
configYaml = string(clashConfigYaml)
configStr = string(clashConfigYaml)
} else if clientType == constant.V2rayN {
hysteria2Url, err := Hysteria2Url(*account.Id, strings.Split(host, ":")[0])
if err != nil {
return "", "", err
}
configStr = hysteria2Url
}

return userInfo, configYaml, nil
return userInfo, configStr, nil
}

func Hysteria2Url(accountId int64, hostname string) (string, error) {
Expand Down

0 comments on commit e5cd580

Please sign in to comment.