-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathbucket_inventory.js
114 lines (102 loc) · 3.56 KB
/
bucket_inventory.js
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
var COS = require('../lib/cos-wx-sdk-v5');
var cos = new COS({
// ForcePathStyle: true, // 如果使用了很多存储桶,可以通过打开后缀式,减少配置白名单域名数量,请求时会用地域域名
getAuthorization: function (options, callback) {
// 异步获取临时密钥
wx.request({
url: 'https://example.com/server/sts.php',
data: {
bucket: options.Bucket,
region: options.Region,
},
dataType: 'json',
success: function (result) {
var data = result.data;
var credentials = data && data.credentials;
if (!data || !credentials) return console.error('credentials invalid');
callback({
TmpSecretId: credentials.tmpSecretId,
TmpSecretKey: credentials.tmpSecretKey,
XCosSecurityToken: credentials.sessionToken,
// 建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
StartTime: data.startTime, // 时间戳,单位秒,如:1580000000
ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
});
}
});
}
});
// 设置存储桶清单任务
function putBucketInventory() {
//.cssg-snippet-body-start:[put-bucket-inventory]
cos.putBucketInventory({
Bucket: 'sourcebucket-1250000000', /* 必须 */
Region: 'ap-beijing', /* 必须 */
Id: 'inventory_test', /* 必须 */
InventoryConfiguration: {
Id: 'inventory_test',
IsEnabled: 'true',
Destination: {
COSBucketDestination: {
Format: 'CSV',
AccountId: '100000000001',
Bucket: 'qcs::cos:ap-beijing::targetbucket-1250000000',
Prefix: 'inventory_test_prefix',
Encryption: {
SSECOS: ''
}
}
},
Schedule: {
Frequency: 'Daily'
},
Filter: {
Prefix: 'filter_prefix'
},
IncludedObjectVersions: 'All',
OptionalFields: [
'Size',
'LastModifiedDate',
'StorageClass',
'ETag'
]
}
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
// 获取存储桶清单任务
function getBucketInventory() {
//.cssg-snippet-body-start:[get-bucket-inventory]
cos.getBucketInventory({
Bucket: 'sourcebucket-1250000000', /* 必须 */
Region: 'ap-beijing', /* 必须 */
Id: 'inventory_test' /* 必须 */
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
// 删除存储桶清单任务
function deleteBucketInventory() {
//.cssg-snippet-body-start:[delete-bucket-inventory]
cos.deleteBucketInventory({
Bucket: 'sourcebucket-1250000000', /* 必须 */
Region: 'ap-beijing', /* 必须 */
Id: 'inventory_test' /* 必须 */
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
//.cssg-methods-pragma
function callBucketInventory() {
// 设置存储桶清单任务
putBucketInventory()
// 获取存储桶清单任务
getBucketInventory()
// 删除存储桶清单任务
deleteBucketInventory()
//.cssg-methods-pragma
}