package apps import ( "strconv" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" ) type AppSettingsAction struct { actionutils.ParentAction } func (this *AppSettingsAction) Init() { this.Nav("httpdns", "app", "settings") } func (this *AppSettingsAction) RunGet(params struct { AppId int64 Section string }) { httpdnsutils.AddLeftMenu(this.Parent()) app, err := findAppMap(this.Parent(), params.AppId) if err != nil { this.ErrorPage(err) return } httpdnsutils.AddAppTabbar(this.Parent(), app.GetString("name"), app.GetInt64("id"), "settings") section := params.Section if len(section) == 0 { section = "basic" } this.Data["activeSection"] = section appIDStr := strconv.FormatInt(app.GetInt64("id"), 10) this.Data["leftMenuItems"] = []maps.Map{ { "name": "基础配置", "url": "/httpdns/apps/app/settings?appId=" + appIDStr + "§ion=basic", "isActive": section == "basic", }, { "name": "认证与密钥", "url": "/httpdns/apps/app/settings?appId=" + appIDStr + "§ion=auth", "isActive": section == "auth", }, } settings := maps.Map{ "appId": app.GetString("appId"), "appStatus": app.GetBool("isOn"), "primaryClusterId": app.GetInt64("primaryClusterId"), "backupClusterId": app.GetInt64("backupClusterId"), "signEnabled": app.GetBool("signEnabled"), "signSecretPlain": app.GetString("signSecretPlain"), "signSecretMasked": app.GetString("signSecretMasked"), "signSecretUpdatedAt": app.GetString("signSecretUpdated"), } this.Data["app"] = app this.Data["settings"] = settings this.Show() } func (this *AppSettingsAction) RunPost(params struct { AppId int64 AppStatus bool Must *actions.Must CSRF *actionutils.CSRF }) { params.Must.Field("appId", params.AppId).Gt(0, "请选择应用") appResp, err := this.RPC().HTTPDNSAppRPC().FindHTTPDNSApp(this.AdminContext(), &pb.FindHTTPDNSAppRequest{ AppDbId: params.AppId, }) if err != nil { this.ErrorPage(err) return } if appResp.GetApp() == nil { this.Fail("找不到对应的应用") return } _, err = this.RPC().HTTPDNSAppRPC().UpdateHTTPDNSApp(this.AdminContext(), &pb.UpdateHTTPDNSAppRequest{ AppDbId: params.AppId, Name: appResp.GetApp().GetName(), PrimaryClusterId: appResp.GetApp().GetPrimaryClusterId(), BackupClusterId: appResp.GetApp().GetBackupClusterId(), IsOn: params.AppStatus, UserId: appResp.GetApp().GetUserId(), }) if err != nil { this.ErrorPage(err) return } this.Success() }