소스 검색

fix(webforwarding): 修复网站转发 HTTPS 配置更新问题- 在编辑网站转发时添加 HTTPS 相关字段的更新
- 优化 HTTPS 配置变更时的处理逻辑
- 确保在更改端口或 HTTPS状态时正确更新 CDN 配置

fusu 1 개월 전
부모
커밋
0793478ffd
2개의 변경된 파일17개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 0
      internal/repository/webforwarding.go
  2. 16 1
      internal/service/webforwarding.go

+ 1 - 0
internal/repository/webforwarding.go

@@ -64,6 +64,7 @@ func (r *webForwardingRepository) AddWebForwarding(ctx context.Context, req *mod
 func (r *webForwardingRepository) EditWebForwarding(ctx context.Context, req *model.WebForwarding) error {
 	forceUpdateFields := map[string]interface{}{
 		"domain": req.Domain,
+		"is_https": req.IsHttps,
 	}
 	// 核心逻辑:
 	// 1. Model(req): 定位要更新的记录。

+ 16 - 1
internal/service/webforwarding.go

@@ -282,6 +282,10 @@ func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1
 		jsonData.SslPolicyRef.IsOn = true
 	} else {
 		apiType = protocolHttp
+		jsonData.SslPolicyRef = v1.SslPolicyRef{
+			IsOn: false,
+			SslPolicyId: req.WebForwardingData.SslCertId,
+		}
 	}
 
 	// 填充通用的 Listen 配置
@@ -449,15 +453,19 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
 	}
 
 	//修改网站端口
-	if oldData.Port != req.WebForwardingData.Port {
+	if oldData.Port != req.WebForwardingData.Port || oldData.IsHttps != req.WebForwardingData.IsHttps || oldData.HttpsCert != req.WebForwardingData.HttpsCert || oldData.HttpsKey != req.WebForwardingData.HttpsKey {
 		var typeJson []byte
+		var closeJson []byte
 		var apiType string
 		if req.WebForwardingData.IsHttps == isHttps {
 			typeJson = formData.HttpsJSON
+			closeJson = formData.HttpJSON
 			apiType = protocolHttps
 		} else {
 			typeJson = formData.HttpJSON
+			closeJson = formData.HttpsJSON
 			apiType = protocolHttp
+
 		}
 		err = s.cdn.EditServerType(ctx, v1.EditWebsite{
 			Id:       int64(oldData.CdnWebId),
@@ -466,6 +474,13 @@ func (s *webForwardingService) EditWebForwarding(ctx context.Context, req *v1.We
 		if err != nil {
 			return err
 		}
+		err = s.cdn.EditServerType(ctx, v1.EditWebsite{
+			Id:       int64(oldData.CdnWebId),
+			TypeJSON: closeJson,
+		}, protocolHttp)
+		if err != nil {
+			return err
+		}
 	}
 
 	//修改网站域名