remove local rule, update xray-core to 1.8.4

This commit is contained in:
Yuzuki616
2023-08-30 14:24:09 +08:00
parent cb868c7411
commit 33ea4702af
7 changed files with 269 additions and 331 deletions

View File

@@ -1,15 +1,14 @@
package panel
import (
"bufio"
"errors"
"fmt"
"log"
"os"
"regexp"
"strconv"
"strings"
"time"
"github.com/sirupsen/logrus"
"github.com/InazumaV/V2bX/conf"
"github.com/go-resty/resty/v2"
)
@@ -17,14 +16,13 @@ import (
// Panel is the interface for different panel's api.
type Client struct {
client *resty.Client
APIHost string
Token string
NodeType string
NodeId int
LocalRuleList []*regexp.Regexp
nodeEtag string
userEtag string
client *resty.Client
APIHost string
Token string
NodeType string
NodeId int
nodeEtag string
userEtag string
}
func New(c *conf.ApiConfig) (*Client, error) {
@@ -36,10 +34,11 @@ func New(c *conf.ApiConfig) (*Client, error) {
client.SetTimeout(5 * time.Second)
}
client.OnError(func(req *resty.Request, err error) {
if v, ok := err.(*resty.ResponseError); ok {
var v *resty.ResponseError
if errors.As(err, &v) {
// v.Response contains the last response from the server
// v.Err contains the original error
log.Print(v.Err)
logrus.Error(v.Err)
}
})
client.SetBaseURL(c.APIHost)
@@ -63,39 +62,11 @@ func New(c *conf.ApiConfig) (*Client, error) {
"node_id": strconv.Itoa(c.NodeID),
"token": c.Key,
})
// Read local rule list
localRuleList := readLocalRuleList(c.RuleListPath)
return &Client{
client: client,
Token: c.Key,
APIHost: c.APIHost,
NodeType: c.NodeType,
NodeId: c.NodeID,
LocalRuleList: localRuleList,
client: client,
Token: c.Key,
APIHost: c.APIHost,
NodeType: c.NodeType,
NodeId: c.NodeID,
}, nil
}
// readLocalRuleList reads the local rule list file
func readLocalRuleList(path string) (LocalRuleList []*regexp.Regexp) {
LocalRuleList = make([]*regexp.Regexp, 0)
if path != "" {
// open the file
file, err := os.Open(path)
//handle errors while opening
if err != nil {
log.Printf("Error when opening file: %s", err)
return
}
fileScanner := bufio.NewScanner(file)
// read line by line
for fileScanner.Scan() {
LocalRuleList = append(LocalRuleList, regexp.MustCompile(fileScanner.Text()))
}
// handle first encountered error while reading
if err := fileScanner.Err(); err != nil {
log.Fatalf("Error while reading file: %s", err)
return
}
}
return
}