mihomo/adapter/provider/subscription_info.go
wwqgtxx 72a126e580
Some checks failed
Build / build (map[abi:1 goarch:loong64 goos:linux output:loong64-abi1]) (push) Failing after 7m5s
Build / build (map[abi:2 goarch:loong64 goos:linux output:loong64-abi2]) (push) Failing after 4m10s
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin goversion:1.20 output:amd64-compatible-go120]) (push) Failing after 2m35s
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin goversion:1.22 output:amd64-compatible-go122]) (push) Failing after 2m47s
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin output:amd64-compatible]) (push) Failing after 2m36s
Build / build (map[goamd64:v1 goarch:amd64 goos:freebsd output:amd64-compatible]) (push) Failing after 2m53s
Build / build (map[goamd64:v1 goarch:amd64 goos:linux goversion:1.20 output:amd64-compatible-go120 test:test]) (push) Failing after 4m52s
Build / build (map[goamd64:v1 goarch:amd64 goos:linux output:amd64-compatible test:test]) (push) Failing after 4m37s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows goversion:1.20 output:amd64-compatible-go120]) (push) Failing after 3m48s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows goversion:1.21 output:amd64-compatible-go121]) (push) Failing after 2m52s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows goversion:1.22 output:amd64-compatible-go122]) (push) Failing after 4m7s
Build / build (map[goamd64:v1 goarch:amd64 goos:windows output:amd64-compatible]) (push) Failing after 2m44s
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin goversion:1.20 output:amd64-go120]) (push) Failing after 3m13s
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin goversion:1.22 output:amd64-go122]) (push) Failing after 3m11s
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin output:amd64]) (push) Failing after 3m23s
Build / build (map[goamd64:v3 goarch:amd64 goos:freebsd output:amd64]) (push) Failing after 3m49s
Build / build (map[goamd64:v3 goarch:amd64 goos:linux goversion:1.20 output:amd64-go120]) (push) Failing after 3m8s
Build / build (map[goamd64:v3 goarch:amd64 goos:linux output:amd64]) (push) Failing after 3m55s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows goversion:1.20 output:amd64-go120]) (push) Failing after 3m6s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows goversion:1.21 output:amd64-go121]) (push) Failing after 3m12s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows goversion:1.22 output:amd64-go122]) (push) Failing after 2m52s
Build / build (map[goamd64:v3 goarch:amd64 goos:windows output:amd64]) (push) Failing after 2m2s
Build / build (map[goarch:386 goos:android ndk:i686-linux-android34 output:386]) (push) Failing after 5m34s
Build / build (map[goarch:386 goos:freebsd output:386]) (push) Failing after 1m32s
Build / build (map[goarch:386 goos:linux goversion:1.20 output:386-go120]) (push) Failing after 3m31s
Build / build (map[goarch:386 goos:linux output:386]) (push) Failing after 3m40s
Build / build (map[goarch:386 goos:windows goversion:1.20 output:386-go120]) (push) Failing after 3m44s
Build / build (map[goarch:386 goos:windows goversion:1.21 output:386-go121]) (push) Failing after 3m18s
Build / build (map[goarch:386 goos:windows goversion:1.22 output:386-go122]) (push) Failing after 2m48s
Build / build (map[goarch:386 goos:windows output:386]) (push) Failing after 2m8s
Build / build (map[goarch:amd64 goos:android ndk:x86_64-linux-android34 output:amd64]) (push) Failing after 4m13s
Build / build (map[goarch:arm goarm:5 goos:linux output:armv5]) (push) Failing after 3m1s
Build / build (map[goarch:arm goarm:6 goos:linux output:armv6]) (push) Failing after 1m32s
Build / build (map[goarch:arm goarm:7 goos:linux output:armv7]) (push) Failing after 3m30s
Build / build (map[goarch:arm goarm:7 goos:windows output:armv7]) (push) Failing after 1m22s
Build / build (map[goarch:arm goos:android ndk:armv7a-linux-androideabi34 output:armv7]) (push) Failing after 4m30s
Build / build (map[goarch:arm64 goos:android ndk:aarch64-linux-android34 output:arm64-v8]) (push) Failing after 5m2s
Build / build (map[goarch:arm64 goos:darwin goversion:1.20 output:arm64-go120]) (push) Failing after 53s
Build / build (map[goarch:arm64 goos:darwin goversion:1.22 output:arm64-go122]) (push) Failing after 3m11s
Build / build (map[goarch:arm64 goos:darwin output:arm64]) (push) Failing after 4m1s
Build / build (map[goarch:arm64 goos:freebsd output:arm64]) (push) Failing after 3m11s
Build / build (map[goarch:arm64 goos:linux output:arm64]) (push) Failing after 1m53s
Build / build (map[goarch:arm64 goos:windows output:arm64]) (push) Failing after 29s
Build / build (map[goarch:mips gomips:hardfloat goos:linux output:mips-hardfloat]) (push) Failing after 33s
Build / build (map[goarch:mips gomips:softfloat goos:linux output:mips-softfloat]) (push) Failing after 2m23s
Build / build (map[goarch:mips64 goos:linux output:mips64]) (push) Failing after 3m47s
Build / build (map[goarch:mips64le goos:linux output:mips64le]) (push) Failing after 53s
Build / build (map[goarch:mipsle gomips:hardfloat goos:linux output:mipsle-hardfloat]) (push) Failing after 46s
Build / build (map[goarch:mipsle gomips:softfloat goos:linux output:mipsle-softfloat]) (push) Failing after 1m1s
Build / build (map[goarch:riscv64 goos:linux output:riscv64]) (push) Failing after 3m57s
Build / build (map[goarch:s390x goos:linux output:s390x]) (push) Failing after 2m0s
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 57s
Build / Upload-Prerelease (push) Has been skipped
Build / Upload-Release (push) Has been skipped
Build / Docker (push) Has been skipped
feat: support inline proxy provider
2024-12-25 10:34:16 +08:00

57 lines
1.1 KiB
Go

package provider
import (
"fmt"
"strconv"
"strings"
"github.com/metacubex/mihomo/log"
)
type SubscriptionInfo struct {
Upload int64
Download int64
Total int64
Expire int64
}
func (info *SubscriptionInfo) Update(userinfo string) {
userinfo = strings.ReplaceAll(strings.ToLower(userinfo), " ", "")
for _, field := range strings.Split(userinfo, ";") {
name, value, ok := strings.Cut(field, "=")
if !ok {
continue
}
intValue, err := parseValue(value)
if err != nil {
log.Warnln("[Provider] get subscription-userinfo: %e", err)
continue
}
switch name {
case "upload":
info.Upload = intValue
case "download":
info.Download = intValue
case "total":
info.Total = intValue
case "expire":
info.Expire = intValue
}
}
}
func parseValue(value string) (int64, error) {
if intValue, err := strconv.ParseInt(value, 10, 64); err == nil {
return intValue, nil
}
if floatValue, err := strconv.ParseFloat(value, 64); err == nil {
return int64(floatValue), nil
}
return 0, fmt.Errorf("failed to parse value '%s'", value)
}