UNPKG

1.14 kBJavaScriptView Raw
1const qiniu = require('qiniu')
2const chalk = require('chalk')
3
4module.exports = function(urls, fn) {
5 let context = this
6 let accessKey = context.accessKey
7 let secretKey = context.secretKey
8 let mac = new qiniu.auth.digest.Mac(accessKey, secretKey)
9 let cdnManager = new qiniu.cdn.CdnManager(mac)
10 let protocolUrls = []
11
12 urls = urls.map(function(value) {
13 if (!/^http(s)?:.*/.test(value)) {
14 return protocolUrls.push('http:' + value, 'https:' + value)
15 } else {
16 return protocolUrls.push(value)
17 }
18 })
19
20 cdnManager.refreshUrls(protocolUrls, function(err, respBody, respInfo) {
21 if (err) {
22 throw err;
23 }
24 if (Number(respInfo.statusCode) === 200) {
25 var jsonBody = JSON.parse(respBody);
26
27 console.log('\n')
28 console.log('Refresh the success')
29 console.log('\n')
30 Object.keys(jsonBody.taskIds || {}).map(function(value) {
31 console.log(chalk.bold.rgb(255, 232, 94)(value + '\n'))
32 })
33
34 fn && fn.apply(context, [err, respBody, respInfo])
35 } else {
36 console.log(chalk.red(' ' + 'Refresh urls failure.'))
37 console.log(respBody)
38 }
39
40 })
41}
\No newline at end of file