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
+1
View File
@@ -6,3 +6,4 @@ dev.go
.DS_Store .DS_Store
develop/jd_cookie develop/jd_cookie
*.cache *.cache
jd_wskey
+32 -14
View File
@@ -4,36 +4,54 @@ import (
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
) )
var name = "sillyGirl" var sillyGirl Bucket = "sillyGirl"
var db *bolt.DB var db *bolt.DB
type Bucket string
func init() { func init() {
var err error var err error
db, err = bolt.Open(ExecPath+"/"+name+".cache", 0600, nil) db, err = bolt.Open(ExecPath+"/sillyGirl.cache", 0600, nil)
if err != nil { if err != nil {
panic(err) 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 { 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 return nil
}) })
} }
func Get(key string) string { func (bucket Bucket) Get(kv ...string) string {
value := "" 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 { 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 nil
}) })
return value 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 ? ?"}, Rules: []string{"set ? ?"},
Handle: func(s im.Sender) interface{} { Handle: func(s im.Sender) interface{} {
Set(s.Get(0), s.Get(1)) sillyGirl.Set(s.Get(0), s.Get(1))
return "设置成功" return "设置成功"
}, },
}, },
{ {
Rules: []string{"delete ?"}, Rules: []string{"delete ?"},
Handle: func(s im.Sender) interface{} { Handle: func(s im.Sender) interface{} {
Set(s.Get(), "") sillyGirl.Set(s.Get(), "")
return "删除成功" return "删除成功"
}, },
}, },
{ {
Rules: []string{"get ?"}, Rules: []string{"get ?"},
Handle: func(s im.Sender) interface{} { Handle: func(s im.Sender) interface{} {
v := Get(s.Get()) v := sillyGirl.Get(s.Get())
if v == "" { if v == "" {
return errors.New("空值") return errors.New("空值")
} }
+9 -1
View File
@@ -1132,7 +1132,15 @@ type UserInfoResult struct {
Timestamp int64 `json:"timestamp"` 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) match := regexp.MustCompile(key + `=([^;]*);{0,1}`).FindStringSubmatch(cookies)
if len(match) == 2 { if len(match) == 2 {
return match[1] return match[1]