2020-09-28 16:25:26 +08:00
|
|
|
package rewrite
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2021-01-03 20:25:15 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
2020-09-28 16:25:26 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DeleteAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *DeleteAction) RunPost(params struct {
|
|
|
|
|
WebId int64
|
|
|
|
|
RewriteRuleId int64
|
|
|
|
|
}) {
|
2020-11-20 15:32:42 +08:00
|
|
|
defer this.CreateLogInfo("从Web %d 中删除重写规则 %d", params.WebId, params.RewriteRuleId)
|
|
|
|
|
|
2021-01-03 20:25:15 +08:00
|
|
|
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithId(this.AdminContext(), params.WebId)
|
2020-09-28 16:25:26 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refs := []*serverconfigs.HTTPRewriteRef{}
|
|
|
|
|
for _, ref := range webConfig.RewriteRefs {
|
|
|
|
|
if ref.RewriteRuleId == params.RewriteRuleId {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
refs = append(refs, ref)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refsJSON, err := json.Marshal(refs)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRewriteRules(this.AdminContext(), &pb.UpdateHTTPWebRewriteRulesRequest{
|
2021-11-24 11:58:01 +08:00
|
|
|
HttpWebId: params.WebId,
|
2020-09-28 16:25:26 +08:00
|
|
|
RewriteRulesJSON: refsJSON,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|