From 676365b13b68f6204387148b9069bdc9182759d9 Mon Sep 17 00:00:00 2001 From: Senis John Date: Wed, 7 Dec 2022 23:26:09 +0800 Subject: [PATCH] update: Add support NewV2board api block rules --- api/newV2board/v2board.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/api/newV2board/v2board.go b/api/newV2board/v2board.go index 9cefea7..4168c35 100644 --- a/api/newV2board/v2board.go +++ b/api/newV2board/v2board.go @@ -248,19 +248,17 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error { // GetNodeRule implements the API interface func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) { ruleList := c.LocalRuleList - if c.NodeType != "V2ray" { - return &ruleList, nil - } - // V2board only support the rule for v2ray - nodeInfoResponse := c.resp.Load().(*simplejson.Json) // todo waiting v2board send configuration - for i, rule := range nodeInfoResponse.Get("rules").MustStringArray() { - rule = strings.TrimPrefix(rule, "regexp:") - ruleListItem := api.DetectRule{ - ID: i, - Pattern: regexp.MustCompile(rule), + nodeInfoResponse := c.resp.Load().(*simplejson.Json) + for i, rule := range nodeInfoResponse.Get("routes").MustArray() { + r := rule.(map[string]any) + if r["action"] == "block" { + ruleListItem := api.DetectRule{ + ID: i, + Pattern: regexp.MustCompile(r["match"].(string)), + } + ruleList = append(ruleList, ruleListItem) } - ruleList = append(ruleList, ruleListItem) } return &ruleList, nil