|
@@ -22,7 +22,7 @@ type AidedWebService interface {
|
|
|
|
|
|
// CDN网站管理
|
|
|
CreateCdnWebsite(ctx context.Context, req *v1.WebForwardingRequest, require RequireResponse, formData v1.Website) (int64, error)
|
|
|
- UpdateCdnConfiguration(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, require RequireResponse, formData v1.Website) error
|
|
|
+ UpdateCdnConfiguration(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, tag string, formData v1.Website) error
|
|
|
DeleteCdnServer(ctx context.Context, cdnWebId int) error
|
|
|
|
|
|
// 源站管理
|
|
@@ -49,7 +49,7 @@ type AidedWebService interface {
|
|
|
|
|
|
// SSL证书管理
|
|
|
ProcessSSLCertificate(ctx context.Context, req *v1.WebForwardingRequest, cdnUid int, formData v1.Website) error
|
|
|
- ProcessSSLCertificateUpdate(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, require RequireResponse) error
|
|
|
+ ProcessSSLCertificateUpdate(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, cdnUid int) error
|
|
|
CleanupSSLCertificate(ctx context.Context, oldData *model.WebForwarding) error
|
|
|
|
|
|
// 数据准备辅助函数
|
|
@@ -604,26 +604,26 @@ func (s *aidedWebService) CreateCdnWebsite(ctx context.Context, req *v1.WebForwa
|
|
|
}
|
|
|
|
|
|
// UpdateCdnConfiguration 更新CDN配置
|
|
|
-func (s *aidedWebService) UpdateCdnConfiguration(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, require RequireResponse, formData v1.Website) error {
|
|
|
+func (s *aidedWebService) UpdateCdnConfiguration(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, tag string, formData v1.Website) error {
|
|
|
// 修改网站端口、协议或证书
|
|
|
if oldData.Port != req.WebForwardingData.Port || oldData.IsHttps != req.WebForwardingData.IsHttps ||
|
|
|
oldData.HttpsCert != req.WebForwardingData.HttpsCert || oldData.HttpsKey != req.WebForwardingData.HttpsKey {
|
|
|
|
|
|
- if err := s.updateWebsiteProtocolAndCert(ctx, req, oldData, require, formData); err != nil {
|
|
|
+ if err := s.updateWebsiteProtocolAndCert(ctx, req.WebForwardingData.IsHttps, int64(oldData.CdnWebId), formData); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 修改网站域名
|
|
|
if oldData.Domain != req.WebForwardingData.Domain {
|
|
|
- if err := s.updateWebsiteDomain(ctx, req, oldData); err != nil {
|
|
|
+ if err := s.updateWebsiteDomain(ctx, req.WebForwardingData.Domain, int64(oldData.CdnWebId)); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 修改网站名字
|
|
|
if oldData.Comment != req.WebForwardingData.Comment {
|
|
|
- if err := s.updateWebsiteBasicInfo(ctx, oldData, require); err != nil {
|
|
|
+ if err := s.updateWebsiteBasicInfo(ctx, int64(oldData.CdnWebId), tag); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -640,22 +640,22 @@ func (s *aidedWebService) DeleteCdnServer(ctx context.Context, cdnWebId int) err
|
|
|
}
|
|
|
|
|
|
// updateWebsiteProtocolAndCert 更新网站协议和证书
|
|
|
-func (s *aidedWebService) updateWebsiteProtocolAndCert(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, require RequireResponse, formData v1.Website) error {
|
|
|
+func (s *aidedWebService) updateWebsiteProtocolAndCert(ctx context.Context, isHttps int, cdnWebId int64, formData v1.Website) error {
|
|
|
|
|
|
|
|
|
// 切换协议
|
|
|
var typeConfig, closeConfig v1.TypeJSON
|
|
|
var apiType, closeType string
|
|
|
|
|
|
- if s.IsHttpsProtocol(req.WebForwardingData.IsHttps) {
|
|
|
+ if s.IsHttpsProtocol(isHttps) {
|
|
|
typeConfig = formData.HttpsJSON
|
|
|
closeConfig = formData.HttpJSON
|
|
|
- apiType = s.GetProtocolType(req.WebForwardingData.IsHttps)
|
|
|
+ apiType = s.GetProtocolType(isHttps)
|
|
|
closeType = s.GetProtocolType(0) // HTTP
|
|
|
} else {
|
|
|
typeConfig = formData.HttpJSON
|
|
|
closeConfig = formData.HttpsJSON
|
|
|
- apiType = s.GetProtocolType(req.WebForwardingData.IsHttps)
|
|
|
+ apiType = s.GetProtocolType(isHttps)
|
|
|
closeType = s.GetProtocolType(1) // HTTPS
|
|
|
}
|
|
|
|
|
@@ -670,14 +670,14 @@ func (s *aidedWebService) updateWebsiteProtocolAndCert(ctx context.Context, req
|
|
|
|
|
|
// 切换协议
|
|
|
if err := s.cdn.EditServerType(ctx, v1.EditWebsite{
|
|
|
- Id: int64(oldData.CdnWebId),
|
|
|
+ Id: cdnWebId,
|
|
|
TypeJSON: typeJson,
|
|
|
}, apiType); err != nil {
|
|
|
return fmt.Errorf("切换到%s协议失败: %w", apiType, err)
|
|
|
}
|
|
|
|
|
|
if err := s.cdn.EditServerType(ctx, v1.EditWebsite{
|
|
|
- Id: int64(oldData.CdnWebId),
|
|
|
+ Id: cdnWebId,
|
|
|
TypeJSON: closeJson,
|
|
|
}, closeType); err != nil {
|
|
|
return fmt.Errorf("关闭%s协议失败: %w", closeType, err)
|
|
@@ -687,14 +687,14 @@ func (s *aidedWebService) updateWebsiteProtocolAndCert(ctx context.Context, req
|
|
|
}
|
|
|
|
|
|
// updateWebsiteDomain 更新网站域名
|
|
|
-func (s *aidedWebService) updateWebsiteDomain(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding) error {
|
|
|
+func (s *aidedWebService) updateWebsiteDomain(ctx context.Context, domain string, cdnWebId int64) error {
|
|
|
type serverName struct {
|
|
|
Name string `json:"name" form:"name"`
|
|
|
Type string `json:"type" form:"type"`
|
|
|
}
|
|
|
var serverData []serverName
|
|
|
serverData = append(serverData, serverName{
|
|
|
- Name: req.WebForwardingData.Domain,
|
|
|
+ Name: domain,
|
|
|
Type: "full",
|
|
|
})
|
|
|
serverJson, err := json.Marshal(serverData)
|
|
@@ -703,7 +703,7 @@ func (s *aidedWebService) updateWebsiteDomain(ctx context.Context, req *v1.WebFo
|
|
|
}
|
|
|
|
|
|
if err := s.cdn.EditServerName(ctx, v1.EditServerNames{
|
|
|
- ServerId: int64(oldData.CdnWebId),
|
|
|
+ ServerId: cdnWebId,
|
|
|
ServerNamesJSON: serverJson,
|
|
|
}); err != nil {
|
|
|
return fmt.Errorf("更新服务器名称失败: %w", err)
|
|
@@ -713,14 +713,14 @@ func (s *aidedWebService) updateWebsiteDomain(ctx context.Context, req *v1.WebFo
|
|
|
}
|
|
|
|
|
|
// updateWebsiteBasicInfo 更新网站基本信息
|
|
|
-func (s *aidedWebService) updateWebsiteBasicInfo(ctx context.Context, oldData *model.WebForwarding, require RequireResponse) error {
|
|
|
+func (s *aidedWebService) updateWebsiteBasicInfo(ctx context.Context, cdnWebId int64, tag string) error {
|
|
|
// 通过globalLimitRep获取节点ID,这是项目中现有的方法
|
|
|
- nodeId, err := s.globalLimitRep.GetNodeId(ctx, oldData.CdnWebId)
|
|
|
+ nodeId, err := s.globalLimitRep.GetNodeId(ctx, int(cdnWebId))
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("获取节点ID失败: %w", err)
|
|
|
}
|
|
|
|
|
|
- if err := s.cdn.EditServerBasic(ctx, int64(oldData.CdnWebId), require.Tag, nodeId); err != nil {
|
|
|
+ if err := s.cdn.EditServerBasic(ctx, cdnWebId, tag, nodeId); err != nil {
|
|
|
return fmt.Errorf("更新服务器基本信息失败: %w", err)
|
|
|
}
|
|
|
|
|
@@ -1058,14 +1058,14 @@ func (s *aidedWebService) CleanupDatabaseRecords(ctx context.Context, id int) er
|
|
|
}
|
|
|
|
|
|
// ProcessSSLCertificateUpdate 处理SSL证书更新
|
|
|
-func (s *aidedWebService) ProcessSSLCertificateUpdate(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, require RequireResponse) error {
|
|
|
+func (s *aidedWebService) ProcessSSLCertificateUpdate(ctx context.Context, req *v1.WebForwardingRequest, oldData *model.WebForwarding, cdnUid int) error {
|
|
|
if !s.IsHttpsProtocol(req.WebForwardingData.IsHttps) {
|
|
|
return nil // 非HTTPS协议不需要处理SSL证书
|
|
|
}
|
|
|
|
|
|
// 如果证书ID为0
|
|
|
if oldData.SslCertId == 0 {
|
|
|
- err := s.ProcessSSLCertificate(ctx, req, require.CdnUid, v1.Website{
|
|
|
+ err := s.ProcessSSLCertificate(ctx, req, cdnUid, v1.Website{
|
|
|
HttpsJSON: v1.TypeJSON{
|
|
|
SslPolicyRef: v1.SslPolicyRef{
|
|
|
SslPolicyId: req.WebForwardingData.SslPolicyId,
|
|
@@ -1085,7 +1085,7 @@ func (s *aidedWebService) ProcessSSLCertificateUpdate(ctx context.Context, req *
|
|
|
CertId: oldData.SslCertId,
|
|
|
CertData: req.WebForwardingData.HttpsCert,
|
|
|
KeyData: req.WebForwardingData.HttpsKey,
|
|
|
- CdnUserId: require.CdnUid,
|
|
|
+ CdnUserId: cdnUid,
|
|
|
Domain: req.WebForwardingData.Domain,
|
|
|
Description: req.WebForwardingData.Comment,
|
|
|
}); err != nil {
|