fix: empty proxy provider subscription info not omitted (#1759)

This commit is contained in:
Mossia 2025-01-07 13:26:56 +08:00 committed by GitHub
parent f4806b49b4
commit 56c128880c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View File

@ -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)
}
})
}

View File

@ -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) {