9 changed files with 170 additions and 28 deletions
@ -1,21 +1,21 @@ |
|||||
package logger |
package logger |
||||
|
|
||||
type Option func(*Logger) |
type Option func(*L) |
||||
|
|
||||
func WithLevel(level Level) Option { |
func WithLevel(level Level) Option { |
||||
return func(logger *Logger) { |
return func(logger *L) { |
||||
logger.Level = level |
logger.Level = level |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
func WithHideTime() Option { |
func WithHideTime() Option { |
||||
return func(logger *Logger) { |
return func(logger *L) { |
||||
logger.HideTime = true |
logger.HideTime = true |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
func WithLengthLimit(limit int) Option { |
func WithLengthLimit(limit int) Option { |
||||
return func(logger *Logger) { |
return func(logger *L) { |
||||
logger.LengthLimit = limit |
logger.LengthLimit = limit |
||||
} |
} |
||||
} |
} |
||||
|
@ -0,0 +1,97 @@ |
|||||
|
package cookiecloud |
||||
|
|
||||
|
import ( |
||||
|
"bytes" |
||||
|
"encoding/json" |
||||
|
"io" |
||||
|
"net/http" |
||||
|
"net/url" |
||||
|
"strings" |
||||
|
|
||||
|
"git.realxlfd.cc/RealXLFD/golib/utils/str" |
||||
|
) |
||||
|
|
||||
|
var ( |
||||
|
data *Data |
||||
|
) |
||||
|
|
||||
|
type Data struct { |
||||
|
CookieData map[string][]CookieDatum `json:"cookie_data"` |
||||
|
LocalStorageData struct{} `json:"local_storage_data"` |
||||
|
UpdateTime string `json:"update_time"` |
||||
|
} |
||||
|
|
||||
|
type CookieDatum struct { |
||||
|
Domain string `json:"domain"` |
||||
|
ExpirationDate *float64 `json:"expirationDate,omitempty"` |
||||
|
HostOnly bool `json:"hostOnly"` |
||||
|
HTTPOnly bool `json:"httpOnly"` |
||||
|
Name string `json:"name"` |
||||
|
Path string `json:"path"` |
||||
|
SameSite SameSite `json:"sameSite"` |
||||
|
Secure bool `json:"secure"` |
||||
|
Session bool `json:"session"` |
||||
|
StoreID string `json:"storeId"` |
||||
|
Value string `json:"value"` |
||||
|
} |
||||
|
|
||||
|
type SameSite string |
||||
|
|
||||
|
const ( |
||||
|
Lax SameSite = "lax" |
||||
|
NoRestriction SameSite = "no_restriction" |
||||
|
Strict SameSite = "strict" |
||||
|
Unspecified SameSite = "unspecified" |
||||
|
) |
||||
|
|
||||
|
func GetData(URL, id, pwd string, proxy ...string) error { |
||||
|
var proxyURL *url.URL |
||||
|
var err error |
||||
|
if len(proxy) != 0 { |
||||
|
proxyURL, err = url.Parse(proxy[0]) |
||||
|
} |
||||
|
if err != nil { |
||||
|
panic(str.T("invalid proxy url: {}", URL)) |
||||
|
} |
||||
|
target, err := url.Parse(URL) |
||||
|
if err != nil { |
||||
|
panic(str.T("invalid url: {}", URL)) |
||||
|
} |
||||
|
requestData := str.Map{"password": pwd}.Json() |
||||
|
request, err := http.NewRequest( |
||||
|
"POST", |
||||
|
target.JoinPath("/get", id).String(), |
||||
|
bytes.NewBuffer(requestData), |
||||
|
) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
request.Header.Set("Content-Type", "application/json") |
||||
|
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}} |
||||
|
resp, err := client.Do(request) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
body, err := io.ReadAll(resp.Body) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
data = &Data{} |
||||
|
return json.Unmarshal(body, data) |
||||
|
} |
||||
|
|
||||
|
func Get(site string) (cookie string, ok bool) { |
||||
|
if len(data.CookieData) == 0 { |
||||
|
return "", false |
||||
|
} |
||||
|
cookies, ok := data.CookieData[str.Join(".", site)] |
||||
|
if !ok { |
||||
|
return "", ok |
||||
|
} |
||||
|
builder := &strings.Builder{} |
||||
|
for i := range cookies { |
||||
|
k, v := cookies[i].Name, cookies[i].Value |
||||
|
builder.WriteString(str.T("{}={};", k, v)) |
||||
|
} |
||||
|
return builder.String(), true |
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
package str |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
"sync" |
||||
|
) |
||||
|
|
||||
|
type Map map[string]string |
||||
|
|
||||
|
func (m Map) Json() []byte { |
||||
|
result, err := json.Marshal(m) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
return result |
||||
|
} |
||||
|
|
||||
|
func KeyFrom(args ...string) *Key { |
||||
|
key := &Key{ |
||||
|
data: map[string]struct{}{}, |
||||
|
lock: &sync.Mutex{}, |
||||
|
} |
||||
|
for i := range args { |
||||
|
key.data[args[i]] = struct{}{} |
||||
|
} |
||||
|
return key |
||||
|
} |
||||
|
|
||||
|
type Key struct { |
||||
|
data map[string]struct{} |
||||
|
lock *sync.Mutex |
||||
|
} |
||||
|
|
||||
|
func (k *Key) Add(args ...string) *Key { |
||||
|
k.lock.Lock() |
||||
|
defer k.lock.Unlock() |
||||
|
for i := range args { |
||||
|
k.data[args[i]] = struct{}{} |
||||
|
} |
||||
|
return k |
||||
|
} |
||||
|
|
||||
|
func (k *Key) Has(key string) bool { |
||||
|
_, ok := k.data[key] |
||||
|
return ok |
||||
|
} |
||||
|
|
||||
|
func (k *Key) Del(keys ...string) *Key { |
||||
|
k.lock.Lock() |
||||
|
defer k.lock.Unlock() |
||||
|
for i := range keys { |
||||
|
delete(k.data, keys[i]) |
||||
|
} |
||||
|
return k |
||||
|
} |
Loading…
Reference in new issue