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

90 lines
2.2 KiB
Go
Raw Normal View History

2021-09-29 20:12:27 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package compression
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2023-06-30 18:08:30 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
2021-09-29 20:12:27 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
2021-09-29 20:12:27 +08:00
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "index")
this.SecondMenu("compression")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
// 只有HTTP服务才支持
if this.FilterHTTPFamily() {
return
}
// 服务分组设置
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{
ServerId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["hasGroupConfig"] = groupResp.HasCompressionConfig
this.Data["groupSettingURL"] = "/servers/groups/group/settings/compression?groupId=" + types.String(groupResp.ServerGroupId)
2021-09-29 20:12:27 +08:00
// WebId
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
this.Data["compressionConfig"] = webConfig.Compression
this.Show()
}
func (this *IndexAction) RunPost(params struct {
WebId int64
CompressionJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
2023-06-30 18:08:30 +08:00
defer this.CreateLogInfo(codes.ServerCompression_LogUpdateCompressionSettings, params.WebId)
2021-09-29 20:12:27 +08:00
// 校验配置
var compressionConfig = &serverconfigs.HTTPCompressionConfig{}
err := json.Unmarshal(params.CompressionJSON, compressionConfig)
if err != nil {
this.Fail("配置校验失败:" + err.Error())
}
err = compressionConfig.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{
2021-11-24 11:58:01 +08:00
HttpWebId: params.WebId,
2021-09-29 20:12:27 +08:00
CompressionJSON: params.CompressionJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}