mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	重写规则API支持用户操作
This commit is contained in:
		@@ -124,8 +124,9 @@ func (this *HTTPRewriteRuleDAO) ComposeRewriteRule(tx *dbs.Tx, rewriteRuleId int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreateRewriteRule 创建规则
 | 
			
		||||
func (this *HTTPRewriteRuleDAO) CreateRewriteRule(tx *dbs.Tx, pattern string, replace string, mode string, redirectStatus int, isBreak bool, proxyHost string, withQuery bool, isOn bool, condsJSON []byte) (int64, error) {
 | 
			
		||||
func (this *HTTPRewriteRuleDAO) CreateRewriteRule(tx *dbs.Tx, userId int64, pattern string, replace string, mode string, redirectStatus int, isBreak bool, proxyHost string, withQuery bool, isOn bool, condsJSON []byte) (int64, error) {
 | 
			
		||||
	var op = NewHTTPRewriteRuleOperator()
 | 
			
		||||
	op.UserId = userId
 | 
			
		||||
	op.State = HTTPRewriteRuleStateEnabled
 | 
			
		||||
	op.IsOn = isOn
 | 
			
		||||
 | 
			
		||||
@@ -172,6 +173,34 @@ func (this *HTTPRewriteRuleDAO) UpdateRewriteRule(tx *dbs.Tx, rewriteRuleId int6
 | 
			
		||||
	return this.NotifyUpdate(tx, rewriteRuleId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *HTTPRewriteRuleDAO) CheckUserRewriteRule(tx *dbs.Tx, userId int64, rewriteRuleId int64) error {
 | 
			
		||||
	if rewriteRuleId <= 0 {
 | 
			
		||||
		return ErrNotFound
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	exists, err := this.Query(tx).
 | 
			
		||||
		Pk(rewriteRuleId).
 | 
			
		||||
		Attr("userId", userId).
 | 
			
		||||
		Exist()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !exists {
 | 
			
		||||
		return ErrNotFound
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithRewriteRuleId(tx, rewriteRuleId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if webId <= 0 {
 | 
			
		||||
		return ErrNotFound
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return SharedHTTPWebDAO.CheckUserWeb(tx, userId, webId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NotifyUpdate 通知更新
 | 
			
		||||
func (this *HTTPRewriteRuleDAO) NotifyUpdate(tx *dbs.Tx, rewriteRuleId int64) error {
 | 
			
		||||
	webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithRewriteRuleId(tx, rewriteRuleId)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user