|
@@ -15,6 +15,7 @@ type GameShieldService interface {
|
|
|
SubmitGameShield(ctx context.Context, req *v1.GameShieldSubmitRequest) (string, error)
|
|
|
EditGameShield(ctx context.Context, req *v1.GameShieldSubmitRequest) (string, error)
|
|
|
DeleteGameShield(ctx context.Context, req int) (string, error)
|
|
|
+ GetGameShieldKey(ctx context.Context, id int) (string, error)
|
|
|
}
|
|
|
|
|
|
func NewGameShieldService(
|
|
@@ -87,8 +88,9 @@ func (service *gameShieldService) SubmitGameShield(ctx context.Context, req *v1.
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
+ dunName := strconv.Itoa(req.Uid) + "_" + strconv.FormatInt(time.Now().Unix(), 10) + "_" + req.AppName
|
|
|
formData := map[string]interface{}{
|
|
|
- "app_name": req.AppName,
|
|
|
+ "app_name": dunName,
|
|
|
"gateway_group_id": 4,
|
|
|
"backend": require.Backend,
|
|
|
"expired_at": require.ExpiredAt,
|
|
@@ -106,13 +108,13 @@ func (service *gameShieldService) SubmitGameShield(ctx context.Context, req *v1.
|
|
|
if res != "" {
|
|
|
return "", fmt.Errorf(res)
|
|
|
}
|
|
|
- KeyAndField, err := service.required.GetKeyAndField(ctx, req.AppName, "rule_id")
|
|
|
+ KeyAndField, err := service.required.GetKeyAndField(ctx, dunName, "rule_id")
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
if err := service.gameShieldRepository.AddGameShield(ctx, &model.GameShield{
|
|
|
AppName: req.AppName,
|
|
|
- GatewayGroupId: 2,
|
|
|
+ GatewayGroupId: 4,
|
|
|
Backend: require.Backend,
|
|
|
RuleId: KeyAndField.FieldId,
|
|
|
Key: KeyAndField.Key,
|
|
@@ -121,6 +123,7 @@ func (service *gameShieldService) SubmitGameShield(ctx context.Context, req *v1.
|
|
|
HostId: req.HostId,
|
|
|
AppIp: req.AppIp,
|
|
|
Checked: req.Checked,
|
|
|
+ DunName: dunName,
|
|
|
}); err != nil {
|
|
|
return "", err
|
|
|
}
|
|
@@ -132,14 +135,16 @@ func (service *gameShieldService) EditGameShield(ctx context.Context, req *v1.Ga
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
- tokenUrl := service.Url + "admin/info/rule/edit?&__goadmin_edit_pk=" + strconv.Itoa(req.RuleId)
|
|
|
+ tokenUrl := service.Url + "admin/info/rule/edit?&__goadmin_edit_pk=" + strconv.Itoa(req.RuleId) + "_" + req.AppName
|
|
|
tokens, err := service.crawlerService.GetFormTokens(ctx, tokenUrl, require.Cookie)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
sendUrl := service.Url + "admin/edit/rule"
|
|
|
+
|
|
|
+ dunName := strconv.Itoa(req.Uid) + "_" + strconv.FormatInt(time.Now().Unix(), 10)
|
|
|
formData := map[string]interface{}{
|
|
|
- "app_name": req.AppName,
|
|
|
+ "app_name": dunName,
|
|
|
"gateway_group_id": 4,
|
|
|
"backend": require.Backend,
|
|
|
"rule_id": req.RuleId,
|
|
@@ -160,13 +165,13 @@ func (service *gameShieldService) EditGameShield(ctx context.Context, req *v1.Ga
|
|
|
if res != "" {
|
|
|
return "", fmt.Errorf(res)
|
|
|
}
|
|
|
- KeyAndField, err := service.required.GetKeyAndField(ctx, req.AppName, "rule_id")
|
|
|
+ KeyAndField, err := service.required.GetKeyAndField(ctx, dunName, "rule_id")
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
if err := service.gameShieldRepository.UpdateGameShield(ctx, &model.GameShield{
|
|
|
AppName: req.AppName,
|
|
|
- GatewayGroupId: 2,
|
|
|
+ GatewayGroupId: 4,
|
|
|
Backend: require.Backend,
|
|
|
RuleId: KeyAndField.FieldId,
|
|
|
Key: KeyAndField.Key,
|
|
@@ -174,6 +179,7 @@ func (service *gameShieldService) EditGameShield(ctx context.Context, req *v1.Ga
|
|
|
HostId: req.HostId,
|
|
|
AppIp: req.AppIp,
|
|
|
Checked: req.Checked,
|
|
|
+ DunName: dunName,
|
|
|
}); err != nil {
|
|
|
return "", err
|
|
|
}
|
|
@@ -195,3 +201,18 @@ func (service *gameShieldService) DeleteGameShield(ctx context.Context, id int)
|
|
|
|
|
|
return res, nil
|
|
|
}
|
|
|
+
|
|
|
+func (service *gameShieldService) GetGameShieldKey(ctx context.Context, id int) (string, error) {
|
|
|
+ dunName, err := service.gameShieldRepository.GetGameShieldIdByAppName(ctx, int64(id))
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ if dunName == "" {
|
|
|
+ return "", fmt.Errorf("没有该条数据")
|
|
|
+ }
|
|
|
+ res, err := service.crawlerService.GetKey(ctx, dunName)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ return res, nil
|
|
|
+}
|