mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-10 17:30:29 +08:00
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package rewrite
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
|
"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
|
|
}) {
|
|
defer this.CreateLogInfo("从Web %d 中删除重写规则 %d", params.WebId, params.RewriteRuleId)
|
|
|
|
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithId(this.AdminContext(), params.WebId)
|
|
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{
|
|
HttpWebId: params.WebId,
|
|
RewriteRulesJSON: refsJSON,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
this.Success()
|
|
}
|