|
| 1 | +package cos |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/xml" |
| 6 | + "net/http" |
| 7 | +) |
| 8 | + |
| 9 | +type FileHashCodeConfig struct { |
| 10 | + Type string `xml:",omitempty"` |
| 11 | + AddToHeader bool `xml:",omitempty"` |
| 12 | +} |
| 13 | + |
| 14 | +type FileHashCodeResult struct { |
| 15 | + MD5 string `xml:",omitempty"` |
| 16 | + SHA1 string `xml:",omitempty"` |
| 17 | + SHA256 string `xml:",omitempty"` |
| 18 | + FileSize int `xml:",omitempty"` |
| 19 | + LastModified string `xml:",omitempty"` |
| 20 | + Etag string `xml:",omitempty"` |
| 21 | +} |
| 22 | + |
| 23 | +type FileUncompressConfig struct { |
| 24 | + Prefix string `xml:",omitempty"` |
| 25 | + PrefixReplaced string `xml:",omitempty"` |
| 26 | +} |
| 27 | + |
| 28 | +type FileUncompressResult struct { |
| 29 | + Region string `xml:",omitempty"` |
| 30 | + Bucket string `xml:",omitempty"` |
| 31 | + FileCount string `xml:",omitempty"` |
| 32 | +} |
| 33 | + |
| 34 | +type FileCompressConfig struct { |
| 35 | + Flatten string `xml:",omitempty"` |
| 36 | + Format string `xml:",omitempty"` |
| 37 | + UrlList string `xml:",omitempty"` |
| 38 | + Prefix string `xml:",omitempty"` |
| 39 | + Key string `xml:",omitempty"` |
| 40 | +} |
| 41 | + |
| 42 | +type FileCompressResult struct { |
| 43 | + Region string `xml:",omitempty"` |
| 44 | + Bucket string `xml:",omitempty"` |
| 45 | + Object string `xml:",omitempty"` |
| 46 | +} |
| 47 | + |
| 48 | +type FileProcessInput FileCompressResult |
| 49 | +type FileProcessOutput FileCompressResult |
| 50 | + |
| 51 | +type FileProcessJobOperation struct { |
| 52 | + FileHashCodeConfig *FileHashCodeConfig `xml:",omitempty"` |
| 53 | + FileHashCodeResult *FileHashCodeResult `xml:",omitempty"` |
| 54 | + FileUncompressConfig *FileUncompressConfig `xml:",omitempty"` |
| 55 | + FileUncompressResult *FileUncompressResult `xml:",omitempty"` |
| 56 | + FileCompressConfig *FileCompressConfig `xml:",omitempty"` |
| 57 | + FileCompressResult *FileCompressResult `xml:",omitempty"` |
| 58 | + Output *FileProcessOutput `xml:",omitempty"` |
| 59 | + UserData string `xml:",omitempty"` |
| 60 | +} |
| 61 | + |
| 62 | +type FileProcessJobOptions struct { |
| 63 | + XMLName xml.Name `xml:"Request"` |
| 64 | + Tag string `xml:",omitempty"` |
| 65 | + Input *FileProcessInput `xml:",omitempty"` |
| 66 | + Operation *FileProcessJobOperation `xml:",omitempty"` |
| 67 | + QueueId string `xml:",omitempty"` |
| 68 | + CallBackFormat string `xml:",omitempty"` |
| 69 | + CallBackType string `xml:",omitempty"` |
| 70 | + CallBack string `xml:",omitempty"` |
| 71 | + CallBackMqConfig string `xml:",omitempty"` |
| 72 | +} |
| 73 | + |
| 74 | +type FileProcessJobResult struct { |
| 75 | + XMLName xml.Name `xml:"Response"` |
| 76 | + JobsDetail *FileProcessJobsDetail `xml:",omitempty"` |
| 77 | +} |
| 78 | + |
| 79 | +type FileProcessJobsDetail struct { |
| 80 | + Code string `xml:",omitempty"` |
| 81 | + Message string `xml:",omitempty"` |
| 82 | + JobId string `xml:",omitempty"` |
| 83 | + Tag string `xml:",omitempty"` |
| 84 | + State string `xml:",omitempty"` |
| 85 | + CreationTime string `xml:",omitempty"` |
| 86 | + StartTime string `xml:",omitempty"` |
| 87 | + EndTime string `xml:",omitempty"` |
| 88 | + QueueId string `xml:",omitempty"` |
| 89 | + Input *FileProcessInput `xml:",omitempty"` |
| 90 | + Operation *FileProcessJobOperation `xml:",omitempty"` |
| 91 | +} |
| 92 | + |
| 93 | +// 提交哈希值计算任务 https://cloud.tencent.com/document/product/436/83108 |
| 94 | +// 提交文件解压任务 https://cloud.tencent.com/document/product/436/83110 |
| 95 | +// 提交多文件打包压缩任务 https://cloud.tencent.com/document/product/436/83112 |
| 96 | +func (s *CIService) CreateFileProcessJob(ctx context.Context, opt *FileProcessJobOptions) (*FileProcessJobResult, *Response, error) { |
| 97 | + var res FileProcessJobResult |
| 98 | + sendOpt := sendOptions{ |
| 99 | + baseURL: s.client.BaseURL.CIURL, |
| 100 | + uri: "/file_jobs", |
| 101 | + method: http.MethodPost, |
| 102 | + body: opt, |
| 103 | + result: &res, |
| 104 | + } |
| 105 | + resp, err := s.client.send(ctx, &sendOpt) |
| 106 | + return &res, resp, err |
| 107 | +} |
| 108 | + |
| 109 | +// 查询哈希值计算结果 https://cloud.tencent.com/document/product/436/83109 |
| 110 | +// 查询文件解压结果 https://cloud.tencent.com/document/product/436/83111 |
| 111 | +// 查询多文件打包压缩结果 https://cloud.tencent.com/document/product/436/83113 |
| 112 | +func (s *CIService) DescribeFileProcessJob(ctx context.Context, jobid string) (*FileProcessJobResult, *Response, error) { |
| 113 | + var res FileProcessJobResult |
| 114 | + sendOpt := sendOptions{ |
| 115 | + baseURL: s.client.BaseURL.CIURL, |
| 116 | + uri: "/file_jobs/" + jobid, |
| 117 | + method: http.MethodGet, |
| 118 | + result: &res, |
| 119 | + } |
| 120 | + resp, err := s.client.send(ctx, &sendOpt) |
| 121 | + return &res, resp, err |
| 122 | +} |
| 123 | + |
| 124 | +// GetFileHashOptions is the option of GetFileHash |
| 125 | +type GetFileHashOptions struct { |
| 126 | + CIProcess string `url:"ci-process,omitempty"` |
| 127 | + Type string `url:"type,omitempty"` |
| 128 | + AddToHeader bool `url:"addtoheader,omitempty"` |
| 129 | +} |
| 130 | + |
| 131 | +// GetFileHashResult is the result of GetFileHash |
| 132 | +type GetFileHashResult struct { |
| 133 | + XMLName xml.Name `xml:"Response"` |
| 134 | + FileHashCodeResult *FileHashCodeResult `xml:",omitempty"` |
| 135 | + Input *FileProcessInput `xml:",omitempty"` |
| 136 | +} |
| 137 | + |
| 138 | +// 哈希值计算同步请求 https://cloud.tencent.com/document/product/436/83107 |
| 139 | +func (s *CIService) GetFileHash(ctx context.Context, name string, opt *GetFileHashOptions) (*GetFileHashResult, *Response, error) { |
| 140 | + var res GetFileHashResult |
| 141 | + sendOpt := sendOptions{ |
| 142 | + baseURL: s.client.BaseURL.BucketURL, |
| 143 | + uri: "/" + encodeURIComponent(name), |
| 144 | + method: http.MethodGet, |
| 145 | + optQuery: opt, |
| 146 | + result: &res, |
| 147 | + } |
| 148 | + resp, err := s.client.send(ctx, &sendOpt) |
| 149 | + return &res, resp, err |
| 150 | +} |
0 commit comments