Files
EdgeAdmin/internal/web/actions/default/servers/server/settings/pages/index.go

78 lines
1.9 KiB
Go
Raw Normal View History

2020-08-21 21:09:42 +08:00
package pages
2023-06-30 18:08:30 +08:00
import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
2021-01-03 20:25:15 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
2020-09-20 08:58:48 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
2021-10-10 10:52:58 +08:00
"github.com/iwind/TeaGo/types"
2020-08-21 21:09:42 +08:00
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "index")
this.SecondMenu("pages")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
2021-10-10 10:52:58 +08:00
// 分组设置
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{
ServerId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["hasGroupConfig"] = groupResp.HasPagesConfig
this.Data["groupSettingURL"] = "/servers/groups/group/settings/pages?groupId=" + types.String(groupResp.ServerGroupId)
2021-01-03 20:25:15 +08:00
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
2020-09-20 08:58:48 +08:00
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
this.Data["pages"] = webConfig.Pages
this.Data["shutdownConfig"] = webConfig.Shutdown
2020-08-21 21:09:42 +08:00
this.Show()
}
2020-09-20 08:58:48 +08:00
func (this *IndexAction) RunPost(params struct {
WebId int64
PagesJSON string
ShutdownJSON string
Must *actions.Must
}) {
2020-11-20 15:32:42 +08:00
// 日志
2023-06-30 18:08:30 +08:00
defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId)
2020-11-20 15:32:42 +08:00
2020-09-20 08:58:48 +08:00
// TODO 检查配置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
2021-11-24 11:58:01 +08:00
HttpWebId: params.WebId,
2020-09-20 08:58:48 +08:00
PagesJSON: []byte(params.PagesJSON),
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
2021-11-24 11:58:01 +08:00
HttpWebId: params.WebId,
2020-09-20 08:58:48 +08:00
ShutdownJSON: []byte(params.ShutdownJSON),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}