forked from Angey40/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baidupcs.go
58 lines (52 loc) · 1.04 KB
/
baidupcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package baidupcs
import (
"fmt"
"github.com/iikira/BaiduPCS-Go/config"
"net/http"
"net/http/cookiejar"
"net/url"
)
// PCSApi 百度 PCS API 详情
type PCSApi struct {
url url.URL
bduss string
writed bool
}
// NewPCS 提供 百度BDUSS, 返回 PCSApi 指针对象
func NewPCS(bduss string) *PCSApi {
return &PCSApi{
url: url.URL{
Scheme: "http",
Host: "pcs.baidu.com",
Path: "/rest/2.0/pcs/",
RawQuery: fmt.Sprintf("app_id=%d", pcsconfig.Config.AppID),
},
bduss: bduss,
writed: false,
}
}
func (p *PCSApi) addItem(subPath, method string, param ...map[string]string) {
if p.writed {
panic("addItem: Already writed")
}
p.url.Path += subPath
uv := p.url.Query()
uv.Set("method", method)
for k := range param {
for k2 := range param[k] {
uv.Set(k2, param[k][k2])
}
}
p.url.RawQuery = uv.Encode()
p.writed = true
}
func (p *PCSApi) getJar() *cookiejar.Jar {
jar, _ := cookiejar.New(nil)
jar.SetCookies(&p.url, []*http.Cookie{
&http.Cookie{
Name: "BDUSS",
Value: p.bduss,
},
})
return jar
}