Ver Fonte

feat(cdn): 实现启用/禁用网站功能

- 新增 EditWebIsOn 方法,用于启用或禁用网站
- 该方法通过 API 调用更新网站的启用状态
- 添加了相应的错误处理和 JSON 反序列化逻辑
fusu há 1 mês atrás
pai
commit
f04f1574fa
1 ficheiros alterados com 23 adições e 0 exclusões
  1. 23 0
      internal/service/cdn.go

+ 23 - 0
internal/service/cdn.go

@@ -52,6 +52,8 @@ type CdnService interface {
 	EditWebSockets(ctx context.Context, req v1.WebSocket) error
 	// 启用webSocket
 	EditHTTPWebWebsocket(ctx context.Context,websocketId int64,websocketJSON []byte) error
+	// 启用/禁用网站
+	EditWebIsOn(ctx context.Context,serverId int64,isOn bool) error
 }
 
 func NewCdnService(
@@ -928,4 +930,25 @@ func (s *cdnService) EditHTTPWebWebsocket(ctx context.Context,websocketId int64,
 		return fmt.Errorf("API 错误: code %d, msg '%s'", res.Code, res.Message)
 	}
 	return nil
+}
+
+// 启用/禁用网站
+func (s *cdnService) EditWebIsOn(ctx context.Context,serverId int64,isOn bool) error {
+	formData := map[string]interface{}{
+		"serverId": serverId,
+		"isOn":     isOn,
+	}
+	apiUrl := s.Url + "ServerService/updateServerIsOn"
+	resBody, err := s.sendDataWithTokenRetry(ctx, formData, apiUrl)
+	if err != nil {
+		return err
+	}
+	var res v1.GeneralResponse[any]
+	if err := json.Unmarshal(resBody, &res); err != nil {
+		return fmt.Errorf("反序列化响应 JSON 失败 (内容: %s): %w", string(resBody), err)
+	}
+	if res.Code != 200 {
+		return fmt.Errorf("API 错误: code %d, msg '%s'", res.Code, res.Message)
+	}
+	return nil
 }