mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
修复修改HTTP Header不会自动更新节点配置的Bug
This commit is contained in:
@@ -36,12 +36,12 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 初始化
|
||||
// Init 初始化
|
||||
func (this *HTTPHeaderDAO) Init() {
|
||||
_ = this.DAOObject.Init()
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableHTTPHeader 启用条目
|
||||
func (this *HTTPHeaderDAO) EnableHTTPHeader(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -50,7 +50,7 @@ func (this *HTTPHeaderDAO) EnableHTTPHeader(tx *dbs.Tx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
// DisableHTTPHeader 禁用条目
|
||||
func (this *HTTPHeaderDAO) DisableHTTPHeader(tx *dbs.Tx, id uint32) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -59,7 +59,7 @@ func (this *HTTPHeaderDAO) DisableHTTPHeader(tx *dbs.Tx, id uint32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
// FindEnabledHTTPHeader 查找启用中的条目
|
||||
func (this *HTTPHeaderDAO) FindEnabledHTTPHeader(tx *dbs.Tx, id int64) (*HTTPHeader, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -71,7 +71,7 @@ func (this *HTTPHeaderDAO) FindEnabledHTTPHeader(tx *dbs.Tx, id int64) (*HTTPHea
|
||||
return result.(*HTTPHeader), err
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
// FindHTTPHeaderName 根据主键查找名称
|
||||
func (this *HTTPHeaderDAO) FindHTTPHeaderName(tx *dbs.Tx, id int64) (string, error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -79,7 +79,7 @@ func (this *HTTPHeaderDAO) FindHTTPHeaderName(tx *dbs.Tx, id int64) (string, err
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 创建Header
|
||||
// CreateHeader 创建Header
|
||||
func (this *HTTPHeaderDAO) CreateHeader(tx *dbs.Tx, name string, value string) (int64, error) {
|
||||
op := NewHTTPHeaderOperator()
|
||||
op.State = HTTPHeaderStateEnabled
|
||||
@@ -103,7 +103,7 @@ func (this *HTTPHeaderDAO) CreateHeader(tx *dbs.Tx, name string, value string) (
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 修改Header
|
||||
// UpdateHeader 修改Header
|
||||
func (this *HTTPHeaderDAO) UpdateHeader(tx *dbs.Tx, headerId int64, name string, value string) error {
|
||||
if headerId <= 0 {
|
||||
return errors.New("invalid headerId")
|
||||
@@ -114,13 +114,14 @@ func (this *HTTPHeaderDAO) UpdateHeader(tx *dbs.Tx, headerId int64, name string,
|
||||
op.Name = name
|
||||
op.Value = value
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO 更新相关配置
|
||||
|
||||
return err
|
||||
return this.NotifyUpdate(tx, headerId)
|
||||
}
|
||||
|
||||
// 组合Header配置
|
||||
// ComposeHeaderConfig 组合Header配置
|
||||
func (this *HTTPHeaderDAO) ComposeHeaderConfig(tx *dbs.Tx, headerId int64) (*shared.HTTPHeaderConfig, error) {
|
||||
header, err := this.FindEnabledHTTPHeader(tx, headerId)
|
||||
if err != nil {
|
||||
@@ -148,7 +149,7 @@ func (this *HTTPHeaderDAO) ComposeHeaderConfig(tx *dbs.Tx, headerId int64) (*sha
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *HTTPHeaderDAO) NotifyUpdate(tx *dbs.Tx, headerId int64) error {
|
||||
policyId, err := SharedHTTPHeaderPolicyDAO.FindHeaderPolicyIdWithHeaderId(tx, headerId)
|
||||
if err != nil {
|
||||
|
||||
@@ -37,12 +37,12 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 初始化
|
||||
// Init 初始化
|
||||
func (this *HTTPHeaderPolicyDAO) Init() {
|
||||
_ = this.DAOObject.Init()
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableHTTPHeaderPolicy 启用条目
|
||||
func (this *HTTPHeaderPolicyDAO) EnableHTTPHeaderPolicy(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -51,7 +51,7 @@ func (this *HTTPHeaderPolicyDAO) EnableHTTPHeaderPolicy(tx *dbs.Tx, id int64) er
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
// DisableHTTPHeaderPolicy 禁用条目
|
||||
func (this *HTTPHeaderPolicyDAO) DisableHTTPHeaderPolicy(tx *dbs.Tx, policyId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(policyId).
|
||||
@@ -63,7 +63,7 @@ func (this *HTTPHeaderPolicyDAO) DisableHTTPHeaderPolicy(tx *dbs.Tx, policyId in
|
||||
return this.NotifyUpdate(tx, policyId)
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
// FindEnabledHTTPHeaderPolicy 查找启用中的条目
|
||||
func (this *HTTPHeaderPolicyDAO) FindEnabledHTTPHeaderPolicy(tx *dbs.Tx, id int64) (*HTTPHeaderPolicy, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -75,7 +75,7 @@ func (this *HTTPHeaderPolicyDAO) FindEnabledHTTPHeaderPolicy(tx *dbs.Tx, id int6
|
||||
return result.(*HTTPHeaderPolicy), err
|
||||
}
|
||||
|
||||
// 创建策略
|
||||
// CreateHeaderPolicy 创建策略
|
||||
func (this *HTTPHeaderPolicyDAO) CreateHeaderPolicy(tx *dbs.Tx) (int64, error) {
|
||||
op := NewHTTPHeaderPolicyOperator()
|
||||
op.IsOn = true
|
||||
@@ -87,7 +87,7 @@ func (this *HTTPHeaderPolicyDAO) CreateHeaderPolicy(tx *dbs.Tx) (int64, error) {
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 修改AddHeaders
|
||||
// UpdateAddingHeaders 修改AddHeaders
|
||||
func (this *HTTPHeaderPolicyDAO) UpdateAddingHeaders(tx *dbs.Tx, policyId int64, headersJSON []byte) error {
|
||||
if policyId <= 0 {
|
||||
return errors.New("invalid policyId")
|
||||
@@ -103,7 +103,7 @@ func (this *HTTPHeaderPolicyDAO) UpdateAddingHeaders(tx *dbs.Tx, policyId int64,
|
||||
return this.NotifyUpdate(tx, policyId)
|
||||
}
|
||||
|
||||
// 修改SetHeaders
|
||||
// UpdateSettingHeaders 修改SetHeaders
|
||||
func (this *HTTPHeaderPolicyDAO) UpdateSettingHeaders(tx *dbs.Tx, policyId int64, headersJSON []byte) error {
|
||||
if policyId <= 0 {
|
||||
return errors.New("invalid policyId")
|
||||
@@ -119,7 +119,7 @@ func (this *HTTPHeaderPolicyDAO) UpdateSettingHeaders(tx *dbs.Tx, policyId int64
|
||||
return this.NotifyUpdate(tx, policyId)
|
||||
}
|
||||
|
||||
// 修改ReplaceHeaders
|
||||
// UpdateReplacingHeaders 修改ReplaceHeaders
|
||||
func (this *HTTPHeaderPolicyDAO) UpdateReplacingHeaders(tx *dbs.Tx, policyId int64, headersJSON []byte) error {
|
||||
if policyId <= 0 {
|
||||
return errors.New("invalid policyId")
|
||||
@@ -135,7 +135,7 @@ func (this *HTTPHeaderPolicyDAO) UpdateReplacingHeaders(tx *dbs.Tx, policyId int
|
||||
return this.NotifyUpdate(tx, policyId)
|
||||
}
|
||||
|
||||
// 修改AddTrailers
|
||||
// UpdateAddingTrailers 修改AddTrailers
|
||||
func (this *HTTPHeaderPolicyDAO) UpdateAddingTrailers(tx *dbs.Tx, policyId int64, headersJSON []byte) error {
|
||||
if policyId <= 0 {
|
||||
return errors.New("invalid policyId")
|
||||
@@ -151,7 +151,7 @@ func (this *HTTPHeaderPolicyDAO) UpdateAddingTrailers(tx *dbs.Tx, policyId int64
|
||||
return this.NotifyUpdate(tx, policyId)
|
||||
}
|
||||
|
||||
// 修改DeleteHeaders
|
||||
// UpdateDeletingHeaders 修改DeleteHeaders
|
||||
func (this *HTTPHeaderPolicyDAO) UpdateDeletingHeaders(tx *dbs.Tx, policyId int64, headerNames []string) error {
|
||||
if policyId <= 0 {
|
||||
return errors.New("invalid policyId")
|
||||
@@ -172,7 +172,7 @@ func (this *HTTPHeaderPolicyDAO) UpdateDeletingHeaders(tx *dbs.Tx, policyId int6
|
||||
return this.NotifyUpdate(tx, policyId)
|
||||
}
|
||||
|
||||
// 组合配置
|
||||
// ComposeHeaderPolicyConfig 组合配置
|
||||
func (this *HTTPHeaderPolicyDAO) ComposeHeaderPolicyConfig(tx *dbs.Tx, headerPolicyId int64) (*shared.HTTPHeaderPolicy, error) {
|
||||
policy, err := this.FindEnabledHTTPHeaderPolicy(tx, headerPolicyId)
|
||||
if err != nil {
|
||||
@@ -292,16 +292,16 @@ func (this *HTTPHeaderPolicyDAO) ComposeHeaderPolicyConfig(tx *dbs.Tx, headerPol
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// 查找Header所在Policy
|
||||
// FindHeaderPolicyIdWithHeaderId 查找Header所在Policy
|
||||
func (this *HTTPHeaderPolicyDAO) FindHeaderPolicyIdWithHeaderId(tx *dbs.Tx, headerId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Where("(JSON_CONTAINS(addHeaders, :jsonQuery) OR JSON_CONTAINS(addTrailers, :jsonQuery) OR JSON_CONTAINS(setHeaders, :jsonQuery) OR JSON_CONTAINS(replaceHeaders, :jsonQuery))").
|
||||
Param("jsonQuery", maps.Map{"id": headerId}.AsJSON()).
|
||||
Param("jsonQuery", maps.Map{"headerId": headerId}.AsJSON()).
|
||||
ResultPk().
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *HTTPHeaderPolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
||||
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithHeaderPolicyId(tx, policyId)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,7 @@ type HTTPWeb struct {
|
||||
ResponseHeader string `field:"responseHeader"` // 响应Header配置
|
||||
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||
Stat string `field:"stat"` // 统计配置
|
||||
Gzip string `field:"gzip"` // Gzip配置(v0.3.2启用)
|
||||
Gzip string `field:"gzip"` // Gzip配置(v0.3.2弃用)
|
||||
Compression string `field:"compression"` // 压缩配置
|
||||
Cache string `field:"cache"` // 缓存配置
|
||||
Firewall string `field:"firewall"` // 防火墙设置
|
||||
@@ -30,6 +30,7 @@ type HTTPWeb struct {
|
||||
HostRedirects string `field:"hostRedirects"` // 域名跳转
|
||||
Fastcgi string `field:"fastcgi"` // Fastcgi配置
|
||||
Auth string `field:"auth"` // 认证策略配置
|
||||
Webp string `field:"webp"` // WebP配置
|
||||
}
|
||||
|
||||
type HTTPWebOperator struct {
|
||||
@@ -61,6 +62,7 @@ type HTTPWebOperator struct {
|
||||
HostRedirects interface{} // 域名跳转
|
||||
Fastcgi interface{} // Fastcgi配置
|
||||
Auth interface{} // 认证策略配置
|
||||
Webp interface{} // WebP配置
|
||||
}
|
||||
|
||||
func NewHTTPWebOperator() *HTTPWebOperator {
|
||||
|
||||
@@ -147,6 +147,32 @@ func (this *HTTPWebService) UpdateHTTPWebCompression(ctx context.Context, req *p
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// UpdateHTTPWebWebP 修改WebP配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebWebP(ctx context.Context, req *pb.UpdateHTTPWebWebPRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
// 检查用户权限
|
||||
err = models.SharedHTTPWebDAO.CheckUserWeb(nil, userId, req.WebId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebWebP(tx, req.WebId, req.WebpJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// UpdateHTTPWebCharset 修改字符集配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.UpdateHTTPWebCharsetRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
|
||||
Reference in New Issue
Block a user