fix11: runtime contracts and smoke stability
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"hy2xs-admin/model/constant"
|
||||
"hy2xs-admin/model/dto"
|
||||
"hy2xs-admin/model/entity"
|
||||
"hy2xs-admin/model/vo"
|
||||
"hy2xs-admin/service"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -83,63 +79,9 @@ func Hysteria2Url(c *gin.Context) {
|
||||
}
|
||||
|
||||
func Hysteria2SubscribeUrl(c *gin.Context) {
|
||||
hysteria2SubscribeUrlDto, err := validateField(c, dto.Hysteria2SubscribeUrlDto{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
subscribeUrl, err := service.Hysteria2SubscribeUrl(*hysteria2SubscribeUrlDto.AccountId,
|
||||
*hysteria2SubscribeUrlDto.Protocol)
|
||||
if err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
return
|
||||
}
|
||||
qrCode, err := qrcode.Encode(subscribeUrl, qrcode.Medium, 300)
|
||||
if err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
return
|
||||
}
|
||||
subscribeVo := vo.Hysteria2SubscribeVo{
|
||||
Url: subscribeUrl,
|
||||
QrCode: qrCode,
|
||||
}
|
||||
vo.Success(subscribeVo, c)
|
||||
vo.Fail("subscription delivery is out of scope in HY2XS baseline", c)
|
||||
}
|
||||
|
||||
func Hysteria2Subscribe(c *gin.Context) {
|
||||
conPass := c.Param("conPass")
|
||||
conPass, err := url.QueryUnescape(conPass)
|
||||
if err != nil {
|
||||
vo.Fail("url decode err", c)
|
||||
return
|
||||
}
|
||||
userAgent := strings.ToLower(c.Request.Header.Get("User-Agent"))
|
||||
|
||||
var clientType string
|
||||
if strings.Contains(userAgent, constant.Shadowrocket) {
|
||||
clientType = constant.Shadowrocket
|
||||
} else if strings.Contains(userAgent, constant.Clash) {
|
||||
clientType = constant.Clash
|
||||
} else if strings.Contains(userAgent, constant.V2rayN) {
|
||||
clientType = constant.V2rayN
|
||||
} else if strings.Contains(userAgent, constant.NekoBox) {
|
||||
clientType = constant.NekoBox
|
||||
} else {
|
||||
clientType = constant.Clash
|
||||
}
|
||||
|
||||
userInfo, configStr, err := service.Hysteria2Subscribe(conPass, clientType)
|
||||
if err != nil {
|
||||
vo.Fail(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if clientType == constant.Shadowrocket || clientType == constant.Clash {
|
||||
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, configStr)
|
||||
vo.Fail("subscription delivery is out of scope in HY2XS baseline", c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user