UNPKG

947 BJavaScriptView Raw
1const qiniu = require('qiniu')
2
3module.exports = function(bucket, proFix, fn) {
4 let context = this
5 let accessKey = context.accessKey
6 let secretKey = context.secretKey
7 let mac = new qiniu.auth.digest.Mac(accessKey, secretKey)
8 let config = new qiniu.conf.Config()
9 let bucketManager = new qiniu.rs.BucketManager(mac, config)
10 let options = {
11 prefix: proFix
12 }
13 let deleteOperations = []
14
15 config.zone = qiniu.zone.Zone_z0
16
17 bucketManager.listPrefix(bucket, options, function(err, respBody, respInfo) {
18 if (err) {
19 console.log(err);
20 throw err;
21 }
22 if (Number(respInfo.statusCode) === 200) {
23 respBody.items.forEach(function(item) {
24 deleteOperations.push(qiniu.rs.deleteOp(bucket, item.key))
25 })
26
27 bucketManager.batch(deleteOperations, function(err, respBody, respInfo) {
28 if (err) {
29 throw err
30 }
31 fn ? fn.apply(context, [mac]) : ''
32 })
33 }
34 });
35
36}
\No newline at end of file