2022-11-05 02:24:08 +08:00
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SubscriptionInfo struct {
|
2022-11-08 22:30:50 +08:00
|
|
|
Upload int64
|
|
|
|
Download int64
|
|
|
|
Total int64
|
|
|
|
Expire int64
|
2022-11-05 02:24:08 +08:00
|
|
|
}
|
|
|
|
|
2023-09-29 08:42:57 +08:00
|
|
|
func NewSubscriptionInfo(userinfo string) (si *SubscriptionInfo, err error) {
|
|
|
|
userinfo = strings.ToLower(userinfo)
|
|
|
|
userinfo = strings.ReplaceAll(userinfo, " ", "")
|
|
|
|
si = new(SubscriptionInfo)
|
|
|
|
for _, field := range strings.Split(userinfo, ";") {
|
|
|
|
switch name, value, _ := strings.Cut(field, "="); name {
|
|
|
|
case "upload":
|
|
|
|
si.Upload, err = strconv.ParseInt(value, 10, 64)
|
|
|
|
case "download":
|
|
|
|
si.Download, err = strconv.ParseInt(value, 10, 64)
|
|
|
|
case "total":
|
|
|
|
si.Total, err = strconv.ParseInt(value, 10, 64)
|
|
|
|
case "expire":
|
2023-11-12 03:17:37 +08:00
|
|
|
if value == "" {
|
|
|
|
si.Expire = 0
|
|
|
|
} else {
|
|
|
|
si.Expire, err = strconv.ParseInt(value, 10, 64)
|
|
|
|
}
|
2023-09-29 08:42:57 +08:00
|
|
|
}
|
2022-11-05 02:24:08 +08:00
|
|
|
if err != nil {
|
2023-09-29 08:42:57 +08:00
|
|
|
return
|
2022-11-05 02:24:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|