This commit is contained in:
cdle
2021-09-15 15:20:28 +08:00
parent 2545606147
commit 6f1fe94e20
4 changed files with 46 additions and 19 deletions
+2 -1
View File
@@ -5,4 +5,5 @@ sillyGirl
dev.go
.DS_Store
develop/jd_cookie
*.cache
*.cache
jd_wskey
+32 -14
View File
@@ -4,36 +4,54 @@ import (
"github.com/boltdb/bolt"
)
var name = "sillyGirl"
var sillyGirl Bucket = "sillyGirl"
var db *bolt.DB
type Bucket string
func init() {
var err error
db, err = bolt.Open(ExecPath+"/"+name+".cache", 0600, nil)
db, err = bolt.Open(ExecPath+"/sillyGirl.cache", 0600, nil)
if err != nil {
panic(err)
}
err = db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(name))
if b == nil {
tx.CreateBucket([]byte(name))
}
return nil
})
}
func Set(key string, value string) {
func (bucket Bucket) Set(key, value string) {
db.Update(func(tx *bolt.Tx) error {
tx.Bucket([]byte(name)).Put([]byte(key), []byte(value))
b := tx.Bucket([]byte(bucket))
if b == nil {
b, _ = tx.CreateBucket([]byte(bucket))
}
b.Put([]byte(key), []byte(value))
return nil
})
}
func Get(key string) string {
value := ""
func (bucket Bucket) Get(kv ...string) string {
var key, value string
for i := range kv {
if i == 0 {
key = kv[0]
} else {
value = kv[1]
}
}
db.View(func(tx *bolt.Tx) error {
value = string(tx.Bucket([]byte(name)).Get([]byte(key)))
b := tx.Bucket([]byte(bucket))
if b == nil {
return nil
}
value = string(b.Get([]byte(key)))
return nil
})
return value
}
func (bucket Bucket) Foreach(f func(k, v []byte) error) {
db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(bucket))
b.ForEach(f)
return nil
})
}
+3 -3
View File
@@ -11,21 +11,21 @@ func init() {
{
Rules: []string{"set ? ?"},
Handle: func(s im.Sender) interface{} {
Set(s.Get(0), s.Get(1))
sillyGirl.Set(s.Get(0), s.Get(1))
return "设置成功"
},
},
{
Rules: []string{"delete ?"},
Handle: func(s im.Sender) interface{} {
Set(s.Get(), "")
sillyGirl.Set(s.Get(), "")
return "删除成功"
},
},
{
Rules: []string{"get ?"},
Handle: func(s im.Sender) interface{} {
v := Get(s.Get())
v := sillyGirl.Get(s.Get())
if v == "" {
return errors.New("空值")
}
+9 -1
View File
@@ -1132,7 +1132,15 @@ type UserInfoResult struct {
Timestamp int64 `json:"timestamp"`
}
func FetchJdCookieValue(key string, cookies string) string {
func FetchJdCookieValue(ps ...string) string {
var key, cookies string
if len(ps) == 2 {
if len(ps[0]) > len(ps[1]) {
key, cookies = ps[1], ps[0]
} else {
key, cookies = ps[0], ps[1]
}
}
match := regexp.MustCompile(key + `=([^;]*);{0,1}`).FindStringSubmatch(cookies)
if len(match) == 2 {
return match[1]