-
Notifications
You must be signed in to change notification settings - Fork 91
/
ci_doc.go
411 lines (371 loc) · 15 KB
/
ci_doc.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
package cos
import (
"bytes"
"context"
"encoding/json"
"encoding/xml"
"io"
"net/http"
"net/url"
)
type DocProcessJobInput struct {
Object string `xml:"Object,omitempty"`
}
type DocProcessJobOutput struct {
Region string `xml:"Region,omitempty"`
Bucket string `xml:"Bucket,omitempty"`
Object string `xml:"Object,omitempty"`
}
type DocProcessJobDocProcess struct {
SrcType string `xml:"SrcType,omitempty"`
TgtType string `xml:"TgtType,omitempty"`
SheetId int `xml:"SheetId,omitempty"`
StartPage int `xml:"StartPage,omitempty"`
EndPage int `xml:"EndPage,omitempty"`
ImageParams string `xml:"ImageParams,omitempty"`
DocPassword string `xml:"DocPassword,omitempty"`
Comments int `xml:"Comments,omitempty"`
PaperDirection int `xml:"PaperDirection,omitempty"`
Quality int `xml:"Quality,omitempty"`
Zoom int `xml:"Zoom,omitempty"`
PaperSize int `xml:"PaperSize,omitempty"`
ImageDpi int `xml:"ImageDpi,omitempty"`
PicPagination int `xml:"PicPagination,omitempty"`
}
type DocProcessJobDocProcessResult struct {
FailPageCount int `xml:",omitempty"`
SuccPageCount int `xml:"SuccPageCount,omitempty"`
TaskId string `xml:"TaskId,omitempty"`
TgtType string `xml:"TgtType,omitempty"`
TotalPageCount int `xml:"TotalPageCount,omitempty"`
TotalSheetCount int `xml:"TotalSheetCount,omitempty"`
PageInfo []struct {
PageNo int `xml:"PageNo,omitempty"`
TgtUri string `xml:"TgtUri,omitempty"`
XSheetPics int `xml:"X-SheetPics,omitempty"`
PicIndex int `xml:"PicIndex,omitempty"`
PicNum int `xml:"PicNum,omitempty"`
} `xml:"PageInfo,omitempty"`
}
type DocProcessJobOperation struct {
Output *DocProcessJobOutput `xml:"Output,omitempty"`
DocProcess *DocProcessJobDocProcess `xml:"DocProcess,omitempty"`
DocProcessResult *DocProcessJobDocProcessResult `xml:"DocProcessResult,omitempty"`
}
type DocProcessJobDetail struct {
Code string `xml:"Code,omitempty"`
Message string `xml:"Message,omitempty"`
JobId string `xml:"JobId,omitempty"`
Tag string `xml:"Tag,omitempty"`
State string `xml:"State,omitempty"`
CreationTime string `xml:"CreationTime,omitempty"`
QueueId string `xml:"QueueId,omitempty"`
Input *DocProcessJobInput `xml:"Input,omitempty"`
Operation *DocProcessJobOperation `xml:"Operation,omitempty"`
}
type CreateDocProcessJobsOptions struct {
XMLName xml.Name `xml:"Request"`
Tag string `xml:"Tag,omitempty"`
Input *DocProcessJobInput `xml:"Input,omitempty"`
Operation *DocProcessJobOperation `xml:"Operation,omitempty"`
QueueId string `xml:"QueueId,omitempty"`
}
type CreateDocProcessJobsResult struct {
XMLName xml.Name `xml:"Response"`
JobsDetail DocProcessJobDetail `xml:"JobsDetail,omitempty"`
}
// 创建文档预览任务 https://cloud.tencent.com/document/product/436/54056
func (s *CIService) CreateDocProcessJobs(ctx context.Context, opt *CreateDocProcessJobsOptions) (*CreateDocProcessJobsResult, *Response, error) {
var res CreateDocProcessJobsResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/doc_jobs",
method: http.MethodPost,
body: opt,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
type DescribeDocProcessJobResult struct {
XMLName xml.Name `xml:"Response"`
JobsDetail *DocProcessJobDetail `xml:"JobsDetail,omitempty"`
NonExistJobIds string `xml:"NonExistJobIds,omitempty"`
}
// 查询文档预览任务 https://cloud.tencent.com/document/product/436/54095
func (s *CIService) DescribeDocProcessJob(ctx context.Context, jobid string) (*DescribeDocProcessJobResult, *Response, error) {
var res DescribeDocProcessJobResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/doc_jobs/" + jobid,
method: http.MethodGet,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
type DescribeDocProcessJobsOptions struct {
QueueId string `url:"queueId,omitempty"`
Tag string `url:"tag,omitempty"`
OrderByTime string `url:"orderByTime,omitempty"`
NextToken string `url:"nextToken,omitempty"`
Size int `url:"size,omitempty"`
States string `url:"states,omitempty"`
StartCreationTime string `url:"startCreationTime,omitempty"`
EndCreationTime string `url:"endCreationTime,omitempty"`
}
type DescribeDocProcessJobsResult struct {
XMLName xml.Name `xml:"Response"`
JobsDetail []DocProcessJobDetail `xml:"JobsDetail,omitempty"`
NextToken string `xml:"NextToken,omitempty"`
}
// 拉取符合条件的文档预览任务 https://cloud.tencent.com/document/product/436/54096
func (s *CIService) DescribeDocProcessJobs(ctx context.Context, opt *DescribeDocProcessJobsOptions) (*DescribeDocProcessJobsResult, *Response, error) {
var res DescribeDocProcessJobsResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/doc_jobs",
optQuery: opt,
method: http.MethodGet,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
type DescribeDocProcessQueuesOptions struct {
QueueIds string `url:"queueIds,omitempty"`
State string `url:"state,omitempty"`
PageNumber int `url:"pageNumber,omitempty"`
PageSize int `url:"pageSize,omitempty"`
}
type DescribeDocProcessQueuesResult struct {
XMLName xml.Name `xml:"Response"`
RequestId string `xml:"RequestId,omitempty"`
TotalCount int `xml:"TotalCount,omitempty"`
PageNumber int `xml:"PageNumber,omitempty"`
PageSize int `xml:"PageSize,omitempty"`
QueueList []DocProcessQueue `xml:"QueueList,omitempty"`
NonExistPIDs []string `xml:"NonExistPIDs,omitempty"`
}
type DocProcessQueue struct {
QueueId string `xml:"QueueId,omitempty"`
Name string `xml:"Name,omitempty"`
State string `xml:"State,omitempty"`
MaxSize int `xml:"MaxSize,omitempty"`
MaxConcurrent int `xml:"MaxConcurrent,omitempty"`
UpdateTime string `xml:"UpdateTime,omitempty"`
CreateTime string `xml:"CreateTime,omitempty"`
NotifyConfig *DocProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
}
type DocProcessQueueNotifyConfig struct {
Url string `xml:"Url,omitempty"`
State string `xml:"State,omitempty"`
Type string `xml:"Type,omitempty"`
Event string `xml:"Event,omitempty"`
}
// 查询文档预览队列 https://cloud.tencent.com/document/product/436/54055
func (s *CIService) DescribeDocProcessQueues(ctx context.Context, opt *DescribeDocProcessQueuesOptions) (*DescribeDocProcessQueuesResult, *Response, error) {
var res DescribeDocProcessQueuesResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/docqueue",
optQuery: opt,
method: http.MethodGet,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
type UpdateDocProcessQueueOptions struct {
XMLName xml.Name `xml:"Request"`
Name string `xml:"Name,omitempty"`
QueueID string `xml:"QueueID,omitempty"`
State string `xml:"State,omitempty"`
NotifyConfig *DocProcessQueueNotifyConfig `xml:"NotifyConfig,omitempty"`
}
type UpdateDocProcessQueueResult struct {
XMLName xml.Name `xml:"Response"`
RequestId string `xml:"RequestId"`
Queue *DocProcessQueue `xml:"Queue"`
}
// 更新文档预览队列 https://cloud.tencent.com/document/product/436/54094
func (s *CIService) UpdateDocProcessQueue(ctx context.Context, opt *UpdateDocProcessQueueOptions) (*UpdateDocProcessQueueResult, *Response, error) {
var res UpdateDocProcessQueueResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/docqueue/" + opt.QueueID,
body: opt,
method: http.MethodPut,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
type DescribeDocProcessBucketsOptions struct {
Regions string `url:"regions,omitempty"`
BucketNames string `url:"bucketNames,omitempty"`
BucketName string `url:"bucketName,omitempty"`
PageNumber int `url:"pageNumber,omitempty"`
PageSize int `url:"pageSize,omitempty"`
}
type DescribeDocProcessBucketsResult struct {
XMLName xml.Name `xml:"Response"`
RequestId string `xml:"RequestId,omitempty"`
TotalCount int `xml:"TotalCount,omitempty"`
PageNumber int `xml:"PageNumber,omitempty"`
PageSize int `xml:"PageSize,omitempty"`
DocBucketList []DocProcessBucket `xml:"DocBucketList,omitempty"`
}
type DocProcessBucket struct {
BucketId string `xml:"BucketId,omitempty"`
Name string `xml:"Name,omitempty"`
Region string `xml:"Region,omitempty"`
CreateTime string `xml:"CreateTime,omitempty"`
AliasBucketId string `xml:"AliasBucketId,omitempty"`
}
// 查询文档预览开通状态 https://cloud.tencent.com/document/product/436/54057
func (s *CIService) DescribeDocProcessBuckets(ctx context.Context, opt *DescribeDocProcessBucketsOptions) (*DescribeDocProcessBucketsResult, *Response, error) {
var res DescribeDocProcessBucketsResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.CIURL,
uri: "/docbucket",
optQuery: opt,
method: http.MethodGet,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return &res, resp, err
}
type DocPreviewOptions struct {
SrcType string `url:"srcType,omitempty"`
Page int `url:"page,omitempty"`
ImageParams string `url:"ImageParams,omitempty"`
Sheet int `url:"sheet,omitempty"`
DstType string `url:"dstType,omitempty"`
Password string `url:"password,omitempty"`
Comment int `url:"comment,omitempty"`
ExcelPaperDirection int `url:"excelPaperDirection,omitempty"`
Quality int `url:"quality,omitempty"`
Zoom int `url:"zoom,omitempty"`
ExcelRow int `url:"excelRow,omitempty"`
ExcelCol int `url:"excelCol,omitempty"`
ExcelPaperSize int `url:"excelPaperSize,omitempty"`
TxtPagination bool `url:"txtPagination,omitempty"`
Scale int `url:"scale,omitempty"`
ImageDpi int `url:"imageDpi,omitempty"`
}
// 同步请求接口 https://cloud.tencent.com/document/product/436/54058
func (s *CIService) DocPreview(ctx context.Context, name string, opt *DocPreviewOptions) (*Response, error) {
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name) + "?ci-process=doc-preview",
optQuery: opt,
method: http.MethodGet,
disableCloseBody: true,
}
resp, err := s.client.send(ctx, &sendOpt)
return resp, err
}
type CIDocCompareOptions struct {
Object string `url:"object,omitempty"`
ComparePath string `url:"comparePath,omitempty"`
CompareUrl string `url:"compareUrl,omitempty"`
SrcType string `url:"srcType,omitempty"`
TgtUri string `url:"tgtUri,omitempty"`
}
type CIDocCompareResult struct {
XMLName xml.Name `xml:"Response"`
Code string `xml:"Code,omitempty" json:"code,omitempty"`
ETag string `xml:"ETag,omitempty" json:"eTag,omitempty"`
Msg string `xml:"Msg,omitempty" json:"msg,omitempty"`
ResultPath string `xml:"ResultPath,omitempty" json:"resultPath,omitempty"`
}
// 优先 json
func (w *CIDocCompareResult) Write(p []byte) (n int, err error) {
err = json.Unmarshal(p, w)
if err != nil {
err = xml.NewDecoder(bytes.NewReader(p)).Decode(w)
if err == nil {
return len(p), nil
}
if err == io.EOF {
err = nil // ignore EOF errors caused by empty response body
}
return 0, err
}
return len(p), nil
}
// DocCompare TODO
func (s *CIService) CIDocCompare(ctx context.Context, opt *CIDocCompareOptions) (*Response, *CIDocCompareResult, error) {
var res CIDocCompareResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/doccompare",
optQuery: opt,
method: http.MethodGet,
disableCloseBody: true,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)
return resp, &res, err
}
type DocPreviewHTMLOptions struct {
DstType string `url:"dstType,omitempty"`
SrcType string `url:"srcType,omitempty"`
WebofficeUrl string `url:"weboffice_url,omitempty"`
TokenUid string `url:"tokenuid,omitempty"`
Sign string `url:"sign,omitempty"`
Copyable string `url:"copyable,omitempty"`
HtmlParams *HtmlParams `url:"htmlParams,omitempty"`
Htmlwaterword string `url:"htmlwaterword,omitempty"`
Htmlfillstyle string `url:"htmlfillstyle,omitempty"`
Htmlfront string `url:"htmlfront,omitempty"`
Htmlrotate string `url:"htmlrotate,omitempty"`
Htmlhorizontal string `url:"htmlhorizontal,omitempty"`
Htmlvertical string `url:"htmlvertical,omitempty"`
}
func (c *HtmlParams) EncodeValues(key string, v *url.Values) error {
config, err := json.Marshal(c)
if err != nil {
return err
}
v.Add("htmlParams", string(config))
return nil
}
type HtmlParams struct {
CommonOptions *HtmlCommonParams `json:"commonOptions,omitempty"`
WordOptions *HtmlWordParams `json:"wordOptions,omitempty"`
PdfOptions *HtmlPdfParams `json:"pdfOptions,omitempty"`
PptOptions *HtmlPptParams `json:"pptOptions,omitempty"`
}
type HtmlCommonParams struct {
IsShowTopArea bool `json:"isShowTopArea"`
IsShowHeader bool `json:"isShowHeader"`
IsBrowserViewFullscreen bool `json:"isBrowserViewFullscreen"`
IsIframeViewFullscreen bool `json:"isIframeViewFullscreen"`
}
type HtmlWordParams struct {
IsShowDocMap bool `json:"isShowDocMap"`
IsBestScale bool `json:"isBestScale"`
IsShowBottomStatusBar bool `json:"isShowBottomStatusBar"`
}
type HtmlPdfParams struct {
IsShowComment bool `json:"isShowComment"`
IsInSafeMode bool `json:"isInSafeMode"`
IsShowBottomStatusBar bool `json:"isShowBottomStatusBar"`
}
type HtmlPptParams struct {
IsShowBottomStatusBar bool `json:"isShowBottomStatusBar"`
}
// 文档转html https://cloud.tencent.com/document/product/460/52518
func (s *CIService) DocPreviewHTML(ctx context.Context, name string, opt *DocPreviewHTMLOptions) (*Response, error) {
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name) + "?ci-process=doc-preview",
optQuery: opt,
method: http.MethodGet,
disableCloseBody: true,
}
resp, err := s.client.send(ctx, &sendOpt)
return resp, err
}