mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-04 12:57:31 +00:00
chore: change subscription-userinfo retrieval
This commit is contained in:
@@ -17,9 +17,10 @@ var (
|
||||
fileMode os.FileMode = 0o666
|
||||
defaultCache *CacheFile
|
||||
|
||||
bucketSelected = []byte("selected")
|
||||
bucketFakeip = []byte("fakeip")
|
||||
bucketETag = []byte("etag")
|
||||
bucketSelected = []byte("selected")
|
||||
bucketFakeip = []byte("fakeip")
|
||||
bucketETag = []byte("etag")
|
||||
bucketSubscriptionInfo = []byte("subscriptioninfo")
|
||||
)
|
||||
|
||||
// CacheFile store and update the cache file
|
||||
|
||||
41
component/profile/cachefile/subscriptioninfo.go
Normal file
41
component/profile/cachefile/subscriptioninfo.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cachefile
|
||||
|
||||
import (
|
||||
"github.com/metacubex/mihomo/log"
|
||||
|
||||
"github.com/metacubex/bbolt"
|
||||
)
|
||||
|
||||
func (c *CacheFile) SetSubscriptionInfo(name string, userInfo string) {
|
||||
if c.DB == nil {
|
||||
return
|
||||
}
|
||||
|
||||
err := c.DB.Batch(func(t *bbolt.Tx) error {
|
||||
bucket, err := t.CreateBucketIfNotExists(bucketSubscriptionInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return bucket.Put([]byte(name), []byte(userInfo))
|
||||
})
|
||||
if err != nil {
|
||||
log.Warnln("[CacheFile] write cache to %s failed: %s", c.DB.Path(), err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
func (c *CacheFile) GetSubscriptionInfo(name string) (userInfo string) {
|
||||
if c.DB == nil {
|
||||
return
|
||||
}
|
||||
c.DB.View(func(t *bbolt.Tx) error {
|
||||
if bucket := t.Bucket(bucketSubscriptionInfo); bucket != nil {
|
||||
if v := bucket.Get([]byte(name)); v != nil {
|
||||
userInfo = string(v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user