forked from Angey40/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm_mkdir.go
80 lines (67 loc) · 1.49 KB
/
rm_mkdir.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package baidupcs
import (
"encoding/json"
"fmt"
"github.com/bitly/go-simplejson"
"github.com/iikira/BaiduPCS-Go/requester"
)
// Remove 批量删除文件/目录
func (p PCSApi) Remove(paths ...string) (err error) {
pathsData := struct {
List []struct {
Path string `json:"path"`
} `json:"list"`
}{}
for k := range paths {
pathsData.List = append(pathsData.List, struct {
Path string `json:"path"`
}{
Path: paths[k],
})
}
ej, err := json.Marshal(&pathsData)
if err != nil {
return
}
p.addItem("file", "delete", map[string]string{
"param": string(ej[:]),
})
h := requester.NewHTTPClient()
body, err := h.Fetch("POST", p.url.String(), nil, map[string]string{
"Cookie": "BDUSS=" + p.bduss,
})
if err != nil {
return
}
json, err := simplejson.NewJson(body)
if err != nil {
return
}
code, err := checkErr(json)
if err != nil {
return fmt.Errorf("删除文件/目录 遇到错误, 错误代码: %d, 消息: %s", code, err)
}
return nil
}
// Mkdir 创建目录
func (p PCSApi) Mkdir(path string) (err error) {
p.addItem("file", "mkdir", map[string]string{
"path": path,
})
h := requester.NewHTTPClient()
body, err := h.Fetch("POST", p.url.String(), nil, map[string]string{
"Cookie": "BDUSS=" + p.bduss,
})
if err != nil {
return
}
json, err := simplejson.NewJson(body)
if err != nil {
return
}
code, err := checkErr(json)
if err != nil {
return fmt.Errorf("创建目录 遇到错误, 错误代码: %d, 消息: %s", code, err)
}
return
}