-
Notifications
You must be signed in to change notification settings - Fork 91
/
ci_fileprocess.go
207 lines (185 loc) · 7.34 KB
/
ci_fileprocess.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package cos
import (
"context"
"encoding/xml"
"net/http"
)
type FileHashCodeConfig struct {
Type string `xml:",omitempty"`
AddToHeader bool `xml:",omitempty"`
}
type FileHashCodeResult struct {
MD5 string `xml:",omitempty"`
SHA1 string `xml:",omitempty"`
SHA256 string `xml:",omitempty"`
FileSize int `xml:",omitempty"`
LastModified string `xml:",omitempty"`
Etag string `xml:",omitempty"`
}
type FileUncompressConfig struct {
Prefix string `xml:",omitempty"`
PrefixReplaced string `xml:",omitempty"`
UnCompressKey string `xml:",omitempty"`
Mode string `xml:",omitempty"`
DownloadConfig *FileUncompressDownloadConfig `xml:",omitempty"`
}
type FileUncompressDownloadConfig struct {
Prefix string `xml:",omitempty"`
Key []string `xml:",omitempty"`
}
type FileUncompressResult struct {
Region string `xml:",omitempty"`
Bucket string `xml:",omitempty"`
FileCount string `xml:",omitempty"`
}
type KeyConfig struct {
Key string `xml:",omitempty"`
Folder string `xml:",omitempty"`
Rename string `xml:",omitempty"`
ImageParams string `xml:",omitempty"`
}
type FileCompressConfig struct {
Flatten string `xml:",omitempty"`
Format string `xml:",omitempty"`
UrlList string `xml:",omitempty"`
Prefix string `xml:",omitempty"`
Key []string `xml:",omitempty"`
Type string `xml:",omitempty"`
CompressKey string `xml:",omitempty"`
IgnoreError string `xml:",omitempty"`
KeyConfig []KeyConfig `xml:",omitempty"`
}
type FileCompressResult struct {
Region string `xml:",omitempty"`
Bucket string `xml:",omitempty"`
Object string `xml:",omitempty"`
CompressFileCount int `xml:",omitempty"`
ErrorCount int `xml:",omitempty"`
ErrorDetail *ErrorDetail `xml:",omitempty"`
}
type ErrorDetail struct {
ErrorCount string `xml:",omitempty"`
ErrorFile []string `xml:",omitempty"`
}
type FileProcessInput FileCompressResult
type FileProcessOutput FileCompressResult
type FileProcessJobOperation struct {
FileHashCodeConfig *FileHashCodeConfig `xml:",omitempty"`
FileHashCodeResult *FileHashCodeResult `xml:",omitempty"`
FileUncompressConfig *FileUncompressConfig `xml:",omitempty"`
FileUncompressResult *FileUncompressResult `xml:",omitempty"`
FileCompressConfig *FileCompressConfig `xml:",omitempty"`
FileCompressResult *FileCompressResult `xml:",omitempty"`
Output *FileProcessOutput `xml:",omitempty"`
UserData string `xml:",omitempty"`
}
type FileProcessJobOptions struct {
XMLName xml.Name `xml:"Request"`
Tag string `xml:",omitempty"`
Input *FileProcessInput `xml:",omitempty"`
Operation *FileProcessJobOperation `xml:",omitempty"`
QueueId string `xml:",omitempty"`
CallBackFormat string `xml:",omitempty"`
CallBackType string `xml:",omitempty"`
CallBack string `xml:",omitempty"`
CallBackMqConfig *NotifyConfigCallBackMqConfig `xml:",omitempty"`
}
type FileProcessJobResult struct {
XMLName xml.Name `xml:"Response"`
JobsDetail *FileProcessJobsDetail `xml:",omitempty"`
}
type FileProcessJobsDetail struct {
Code string `xml:",omitempty"`
Message string `xml:",omitempty"`
JobId string `xml:",omitempty"`
Tag string `xml:",omitempty"`
State string `xml:",omitempty"`
CreationTime string `xml:",omitempty"`
StartTime string `xml:",omitempty"`
EndTime string `xml:",omitempty"`
QueueId string `xml:",omitempty"`
Progress int `xml:",omitempty"`
Input *FileProcessInput `xml:",omitempty"`
Operation *FileProcessJobOperation `xml:",omitempty"`
}
// 提交哈希值计算任务 https://cloud.tencent.com/document/product/436/83108
// 提交文件解压任务 https://cloud.tencent.com/document/product/436/83110
// 提交多文件打包压缩任务 https://cloud.tencent.com/document/product/436/83112
func (s *CIService) CreateFileProcessJob(ctx context.Context, opt *FileProcessJobOptions) (*FileProcessJobResult, *Response, error) {
var res FileProcessJobResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/file_jobs",
method: http.MethodPost,
body: opt,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
// 查询哈希值计算结果 https://cloud.tencent.com/document/product/436/83109
// 查询文件解压结果 https://cloud.tencent.com/document/product/436/83111
// 查询多文件打包压缩结果 https://cloud.tencent.com/document/product/436/83113
func (s *CIService) DescribeFileProcessJob(ctx context.Context, jobid string) (*FileProcessJobResult, *Response, error) {
var res FileProcessJobResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/file_jobs/" + jobid,
method: http.MethodGet,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
// GetFileHashOptions is the option of GetFileHash
type GetFileHashOptions struct {
CIProcess string `url:"ci-process,omitempty"`
Type string `url:"type,omitempty"`
AddToHeader bool `url:"addtoheader,omitempty"`
}
// GetFileHashResult is the result of GetFileHash
type GetFileHashResult struct {
XMLName xml.Name `xml:"Response"`
FileHashCodeResult *FileHashCodeResult `xml:",omitempty"`
Input *FileProcessInput `xml:",omitempty"`
}
// 哈希值计算同步请求 https://cloud.tencent.com/document/product/436/83107
func (s *CIService) GetFileHash(ctx context.Context, name string, opt *GetFileHashOptions) (*GetFileHashResult, *Response, error) {
var res GetFileHashResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name),
method: http.MethodGet,
optQuery: opt,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
// ZipPreviewResult 压缩包预览结果
type ZipPreviewResult struct {
XMLName xml.Name `xml:"Response"`
FileNumber int `xml:"FileNumber,omitempty"`
IsTruncated bool `xml:"IsTruncated,omitempty"`
Contents []*struct {
Key string `xml:"Key,omitempty"`
LastModified string `xml:"LastModified,omitempty"`
UncompressedSize int `xml:"UncompressedSize,omitempty"`
} `xml:"Contents,omitempty"`
}
// ZipPreview 压缩包预览
func (s *CIService) ZipPreview(ctx context.Context, name, uncompress_key string) (*ZipPreviewResult, *Response, error) {
var res ZipPreviewResult
uriStr := "/" + encodeURIComponent(name) + "?ci-process=zippreview"
if uncompress_key != "" {
uriStr += "&uncompress-key=" + encodeURIComponent(uncompress_key)
}
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: uriStr,
method: http.MethodGet,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}