Полный продовый фикс HY2XS/Hysteria2: auth DTO, валидация bind, smoke, URI, preflight и env-контракт

This commit is contained in:
2026-05-08 05:06:29 +05:00
parent 4b382d6ef9
commit d2898ac10c
10 changed files with 49 additions and 23 deletions
+7 -2
View File
@@ -26,12 +26,17 @@ func validateStr(f validator.FieldLevel) bool {
}
func validateField[T interface{}](c *gin.Context, field T) (T, error) {
var bindErr error
if c.Request.Method == http.MethodGet {
_ = c.ShouldBindQuery(&field)
bindErr = c.ShouldBindQuery(&field)
} else if c.Request.Method == http.MethodPost ||
c.Request.Method == http.MethodPut ||
c.Request.Method == http.MethodDelete {
_ = c.ShouldBindJSON(&field)
bindErr = c.ShouldBindJSON(&field)
}
if bindErr != nil {
vo.Fail(constant.InvalidError, c)
return field, fmt.Errorf(constant.InvalidError)
}
if err := validate.Struct(&field); err != nil {
vo.Fail(constant.InvalidError, c)
+1 -1
View File
@@ -3,7 +3,7 @@ package dto
type Hysteria2AuthDto struct {
Addr *string `json:"addr" form:"addr" validate:"required"`
Auth *string `json:"auth" form:"auth" validate:"required"`
Tx *string `json:"tx" form:"tx" validate:"required"`
Tx *int64 `json:"tx" form:"tx" validate:"required"`
}
type Hysteria2KickDto struct {
-9
View File
@@ -270,19 +270,10 @@ func Hysteria2Url(accountId int64) (string, error) {
hysteria2Config.ACME.Domains != nil &&
len(hysteria2Config.ACME.Domains) > 0 {
urlConfig += fmt.Sprintf("&sni=%s", hysteria2Config.ACME.Domains[0])
// shadowrocket
urlConfig += fmt.Sprintf("&peer=%s", hysteria2Config.ACME.Domains[0])
}
urlConfig += "&insecure=0"
if hysteria2Config.Bandwidth != nil &&
hysteria2Config.Bandwidth.Down != nil &&
*hysteria2Config.Bandwidth.Down != "" {
// shadowrocket
urlConfig += fmt.Sprintf("&downmbps=%s", url.PathEscape(*hysteria2Config.Bandwidth.Down))
}
hysteria2ConfigRemark, err := dao.GetConfig("key = ?", constant.Hysteria2ConfigRemark)
if err != nil {
return "", err