chore: 暴露数据给前端

This commit is contained in:
adlyq
2022-05-17 16:47:21 +08:00
parent 0742f7db26
commit c4408612b3
5 changed files with 57 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package route
import (
"github.com/Dreamacro/clash/constant"
"net/http"
"github.com/Dreamacro/clash/tunnel"
@ -19,17 +20,23 @@ type Rule struct {
Type string `json:"type"`
Payload string `json:"payload"`
Proxy string `json:"proxy"`
Size int `json:"Size"`
}
func getRules(w http.ResponseWriter, r *http.Request) {
rawRules := tunnel.Rules()
rules := []Rule{}
for _, rule := range rawRules {
rules = append(rules, Rule{
r := Rule{
Type: rule.RuleType().String(),
Payload: rule.Payload(),
Proxy: rule.Adapter(),
})
Size: -1,
}
if rule.RuleType() == constant.GEOIP || rule.RuleType() == constant.GEOSITE {
r.Size = rule.(constant.RuleGroup).GetRecodeSize()
}
rules = append(rules, r)
}