|
@@ -11,7 +11,9 @@ import (
|
|
|
)
|
|
|
|
|
|
type CdnService interface {
|
|
|
+ // GetToken 获取token
|
|
|
GetToken(ctx context.Context) (string, error)
|
|
|
+ // AddUser 注册用户
|
|
|
AddUser(ctx context.Context, req v1.User) (int64, error)
|
|
|
CreateGroup(ctx context.Context, req v1.Group) (int64, error)
|
|
|
BindPlan(ctx context.Context, req v1.Plan) (int64, error)
|
|
@@ -22,6 +24,13 @@ type CdnService interface {
|
|
|
CreateOrigin(ctx context.Context, req v1.Origin) (int64, error)
|
|
|
EditOrigin(ctx context.Context, req v1.Origin) error
|
|
|
AddServerOrigin(ctx context.Context, serverId int64, originId int64) error
|
|
|
+ EditOriginIsOn(ctx context.Context, originId int64, isOn bool) error
|
|
|
+ // 修改网站基本信息
|
|
|
+ EditServerBasic (ctx context.Context, serverId int64,name string) error
|
|
|
+ // 从网站中删除某个源站
|
|
|
+ DelServerOrigin (ctx context.Context,serverId int64, originId int64) error
|
|
|
+ // 删除网站
|
|
|
+ DelServer(ctx context.Context, serverId int64) error
|
|
|
}
|
|
|
|
|
|
func NewCdnService(
|
|
@@ -398,6 +407,7 @@ func (s *cdnService) CreateOrigin(ctx context.Context, req v1.Origin) (int64, er
|
|
|
return res.Data.OriginId, nil
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func (s *cdnService) EditServerType(ctx context.Context, req v1.EditWebsite,apiType string) error {
|
|
|
typeName := apiType + "JSON"
|
|
|
formData := map[string]interface{}{
|
|
@@ -420,6 +430,8 @@ func (s *cdnService) EditServerType(ctx context.Context, req v1.EditWebsite,apiT
|
|
|
|
|
|
}
|
|
|
|
|
|
+// EditOrigin 编辑源站
|
|
|
+
|
|
|
func (s *cdnService) EditOrigin(ctx context.Context, req v1.Origin) error {
|
|
|
formData := map[string]interface{}{
|
|
|
"originId": req.OriginId,
|
|
@@ -451,6 +463,8 @@ func (s *cdnService) EditOrigin(ctx context.Context, req v1.Origin) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// AddServerOrigin 网站绑定源站
|
|
|
func (s *cdnService) AddServerOrigin(ctx context.Context, serverId int64, originId int64) error {
|
|
|
formData := map[string]interface{}{
|
|
|
"serverId": serverId,
|
|
@@ -458,7 +472,91 @@ func (s *cdnService) AddServerOrigin(ctx context.Context, serverId int64, origin
|
|
|
"isPrimary": true,
|
|
|
}
|
|
|
apiUrl := s.Url + "ServerService/addServerOrigin"
|
|
|
- resBody, err := s.sendDataWithTokenRetry(ctx, formData, apiUrl) // 使用封装后的方法
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+// EditOriginIsOn 编辑源站是否开启
|
|
|
+func (s *cdnService) EditOriginIsOn(ctx context.Context, originId int64, isOn bool) error {
|
|
|
+ formData := map[string]interface{}{
|
|
|
+ "originId": originId,
|
|
|
+ "isOn": isOn,
|
|
|
+ }
|
|
|
+ apiUrl := s.Url + "OriginService/updateOriginIsOn"
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+// EditServerBasic 修改网站基本信息
|
|
|
+func (s *cdnService) EditServerBasic (ctx context.Context, serverId int64,name string) error {
|
|
|
+ formData := map[string]interface{}{
|
|
|
+ "serverId": serverId,
|
|
|
+ "name": name,
|
|
|
+ "nodeClusterId" : 1,
|
|
|
+ "isOn": true,
|
|
|
+ }
|
|
|
+ apiUrl := s.Url + "ServerService/updateServerBasic"
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+// DelServerOrigin 从网站中删除某个源站
|
|
|
+func (s *cdnService) DelServerOrigin (ctx context.Context,serverId int64, originId int64) error {
|
|
|
+ formData := map[string]interface{}{
|
|
|
+ "serverId": serverId,
|
|
|
+ "originId": originId,
|
|
|
+ }
|
|
|
+ apiUrl := s.Url + "ServerService/deleteServerOrigin"
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+func (s *cdnService) DelServer(ctx context.Context, serverId int64) error {
|
|
|
+ formData := map[string]interface{}{
|
|
|
+ "serverId": serverId,
|
|
|
+ }
|
|
|
+ apiUrl := s.Url + "ServerService/deleteServer"
|
|
|
+ resBody, err := s.sendDataWithTokenRetry(ctx, formData, apiUrl)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|