mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-11 19:42:29 +08:00
fix: empty proxy provider subscription info not omitted (#1759)
This commit is contained in:
parent
f4806b49b4
commit
56c128880c
@ -137,7 +137,7 @@ func (pp *proxySetProvider) Initial() error {
|
||||
return err
|
||||
}
|
||||
if subscriptionInfo := cachefile.Cache().GetSubscriptionInfo(pp.Name()); subscriptionInfo != "" {
|
||||
pp.subscriptionInfo.Update(subscriptionInfo)
|
||||
pp.subscriptionInfo = NewSubscriptionInfo(subscriptionInfo)
|
||||
}
|
||||
pp.closeAllConnections()
|
||||
return nil
|
||||
@ -165,14 +165,12 @@ func NewProxySetProvider(name string, interval time.Duration, parser resource.Pa
|
||||
go hc.process()
|
||||
}
|
||||
|
||||
si := new(SubscriptionInfo)
|
||||
pd := &proxySetProvider{
|
||||
baseProvider: baseProvider{
|
||||
name: name,
|
||||
proxies: []C.Proxy{},
|
||||
healthCheck: hc,
|
||||
},
|
||||
subscriptionInfo: si,
|
||||
}
|
||||
|
||||
fetcher := resource.NewFetcher[[]C.Proxy](name, interval, vehicle, parser, proxiesOnUpdate(pd))
|
||||
@ -181,7 +179,7 @@ func NewProxySetProvider(name string, interval time.Duration, parser resource.Pa
|
||||
httpVehicle.SetInRead(func(resp *http.Response) {
|
||||
if subscriptionInfo := resp.Header.Get("subscription-userinfo"); subscriptionInfo != "" {
|
||||
cachefile.Cache().SetSubscriptionInfo(name, subscriptionInfo)
|
||||
si.Update(subscriptionInfo)
|
||||
pd.subscriptionInfo = NewSubscriptionInfo(subscriptionInfo)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -15,8 +15,9 @@ type SubscriptionInfo struct {
|
||||
Expire int64
|
||||
}
|
||||
|
||||
func (info *SubscriptionInfo) Update(userinfo string) {
|
||||
func NewSubscriptionInfo(userinfo string) (si *SubscriptionInfo) {
|
||||
userinfo = strings.ReplaceAll(strings.ToLower(userinfo), " ", "")
|
||||
si = new(SubscriptionInfo)
|
||||
|
||||
for _, field := range strings.Split(userinfo, ";") {
|
||||
name, value, ok := strings.Cut(field, "=")
|
||||
@ -32,15 +33,16 @@ func (info *SubscriptionInfo) Update(userinfo string) {
|
||||
|
||||
switch name {
|
||||
case "upload":
|
||||
info.Upload = intValue
|
||||
si.Upload = intValue
|
||||
case "download":
|
||||
info.Download = intValue
|
||||
si.Download = intValue
|
||||
case "total":
|
||||
info.Total = intValue
|
||||
si.Total = intValue
|
||||
case "expire":
|
||||
info.Expire = intValue
|
||||
si.Expire = intValue
|
||||
}
|
||||
}
|
||||
return si
|
||||
}
|
||||
|
||||
func parseValue(value string) (int64, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user