/
file_list.go
71 lines (63 loc) · 2.07 KB
/
file_list.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
package pcs
import (
"encoding/json"
"fmt"
"net/url"
)
type ResponseFileList struct {
List []ResponseFileListDetail `json:"list"`
Request_id uint64 `json:"request_id"`
}
type ResponseFileListDetail struct {
Fs_id uint64 `json:"fs_id"`
Path string `json:"path"`
Ctime int64 `json:"ctime"`
Mtime int64 `json:"mtime"`
Md5 string `json:"md5"`
Size uint64 `json:"size"` //文件大小(byte)。
IsDir uint64 `json:"isdir"` //0为文件 1为目录
}
func (rt *ResponseFileList) String() string {
bf, _ := json.Marshal(rt)
return string(bf)
}
const (
FileList_OrderBy_MTime = "time" //修改时间
FileList_OrderBy_Name = "name" //文件名
FileList_OrderBy_Size = "size" //大小,注意目录无大小
FileList_Order_Asc = "asc" //升序
FileList_Order_Desc = "desc" //降序 缺省采用降序排序
)
/**
*@param path string
*@param orderby string 排序字段
*@param order string 排序方式
*@param offset int 结果集偏移量 从0开始
*@param limit int 结果集条数
*/
func (pcs *Pcs) FileList(path string, orderby string, order string, offset int, limit int) (info *ResponseFileList, pcs_err *PcsError) {
url_values := url.Values{}
url_values.Add("path", path)
if orderby != "" {
if orderby == FileList_OrderBy_MTime || orderby == FileList_OrderBy_Name || orderby == FileList_OrderBy_Size {
url_values.Add("by", orderby)
} else {
panic(fmt.Sprintf("unknow order field [%s],only sup:[time|name|size]", orderby))
}
}
if order != "" {
if order == FileList_Order_Asc || order == FileList_Order_Desc {
url_values.Add("order", order)
} else {
panic(fmt.Sprintf("unknow order method [%s],only sup:[asc|desc]", order))
}
}
if limit > 0 && offset >= 0 {
url_values.Add("limit", fmt.Sprintf("%d-%d", offset, offset+limit))
}
_, _, pcs_err = pcs.QuickRequest(pcs.BuildRequest(GET, "file?method=list&"+url_values.Encode(), nil), &info)
return info, pcs_err
}
func (pcs *Pcs) FileListEasy(path string) (*ResponseFileList, *PcsError) {
return pcs.FileList(path, FileList_OrderBy_Name, FileList_Order_Desc, 0, 0)
}