Skip to content

Commit 676365b

Browse files
committed
update: Add support NewV2board api block rules
1 parent e774d5c commit 676365b

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

api/newV2board/v2board.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,17 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
248248
// GetNodeRule implements the API interface
249249
func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
250250
ruleList := c.LocalRuleList
251-
if c.NodeType != "V2ray" {
252-
return &ruleList, nil
253-
}
254251

255-
// V2board only support the rule for v2ray
256-
nodeInfoResponse := c.resp.Load().(*simplejson.Json) // todo waiting v2board send configuration
257-
for i, rule := range nodeInfoResponse.Get("rules").MustStringArray() {
258-
rule = strings.TrimPrefix(rule, "regexp:")
259-
ruleListItem := api.DetectRule{
260-
ID: i,
261-
Pattern: regexp.MustCompile(rule),
252+
nodeInfoResponse := c.resp.Load().(*simplejson.Json)
253+
for i, rule := range nodeInfoResponse.Get("routes").MustArray() {
254+
r := rule.(map[string]any)
255+
if r["action"] == "block" {
256+
ruleListItem := api.DetectRule{
257+
ID: i,
258+
Pattern: regexp.MustCompile(r["match"].(string)),
259+
}
260+
ruleList = append(ruleList, ruleListItem)
262261
}
263-
ruleList = append(ruleList, ruleListItem)
264262
}
265263

266264
return &ruleList, nil

0 commit comments

Comments
 (0)