-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi-option.go
156 lines (133 loc) · 2.62 KB
/
api-option.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package mopan
import (
"strconv"
)
type ParamOption func(Json)
func WarpParamOption(option ...ParamOption) []ParamOption {
return option
}
func ApplyParamOption(param Json, option ...ParamOption) Json {
for _, opt := range option {
opt(param)
}
return param
}
// 查询每页大小
func QueryFileOptionPageSize(size int) ParamOption {
return func(j Json) {
j["pageSize"] = strconv.Itoa(size)
}
}
type IconOption int8
const (
IconSmall IconOption = (1 << iota)
IconMedium
IconLarge
IconMax600
)
// 返回icon方案
// 关闭: icon 0
func QueryFileOptionIconOption(icon IconOption) ParamOption {
return func(j Json) {
j["iconOption"] = icon
}
}
type OrderBy int8
const (
S_FileName OrderBy = iota
S_LastOpTime
S_FileSize
)
// 数据排序
func QueryFileOptionSort(orderBy OrderBy, desc bool) ParamOption {
return func(j Json) {
switch orderBy {
case S_FileSize:
j["orderBy"] = "filesize"
case S_LastOpTime:
j["orderBy"] = "lastOpTime"
case S_FileName:
fallthrough
default:
j["orderBy"] = "filename"
}
j["descending"] = desc
}
}
// 查询媒体信息
// 似乎没用
func QueryFileOptionMediaAttr(flag bool) ParamOption {
return func(j Json) {
j["mediaAttr"] = Bool2Int(flag)
}
}
type fileType int16
const (
AllType fileType = iota
FileType
FolderType
ImageType
AudioType
VideoType
DocumentType
)
func QueryFileOptionFileType(fileType fileType) ParamOption {
return func(j Json) {
switch fileType {
case FileType:
j["fileType"] = 1
case FolderType:
j["fileType"] = 2
case AllType, ImageType, AudioType, VideoType, DocumentType:
fallthrough
default:
j["fileType"] = 0
}
switch fileType {
case ImageType:
j["mediaType"] = 1
case AudioType:
j["mediaType"] = 2
case VideoType:
j["mediaType"] = 3
case DocumentType:
j["mediaType"] = 4
case AllType, FileType, FolderType:
fallthrough
default:
j["mediaType"] = 0
}
}
}
// 是否递归搜索
func SearchFilesOptionRecursive(recursive bool) ParamOption {
return func(j Json) {
j["recursive"] = Bool2Int(recursive)
}
}
// 通用: 查询共享空间
// 如果 cloudId 为空则不做任何操作
func ParamOptionShareFile(cloudId string) ParamOption {
return func(j Json) {
if cloudId != "" {
j["source"] = 2
j["cloudId"] = cloudId
}
}
}
type updloadOpertype int
const (
U_Rename updloadOpertype = 1
U_Overwrite updloadOpertype = 3
)
func UpdloadOptionOpertype(opertype updloadOpertype) ParamOption {
return func(j Json) {
j["opertype"] = opertype
}
}
// 通用: 查询相册
// func QureyOptionAlbumFile() ParamOption {
// return func(j Json) {
// j["type"] = 2
// }
// }