Skip to content

Instantly share code, notes, and snippets.

@shanelau
Last active June 23, 2016 08:42
Show Gist options
  • Save shanelau/e5c8faf2162359dfb6765299bf8c3b5b to your computer and use it in GitHub Desktop.
Save shanelau/e5c8faf2162359dfb6765299bf8c3b5b to your computer and use it in GitHub Desktop.
refresh cache for upyun by nodejs
/**
* Created by liuxing on 16/6/23.
*/
var request = require('request');
var crypto = require('crypto');
var UPYUN_CACHE = 'http://purge.upyun.com/purge/';
function md5sum(data) {
var md5 = crypto.createHash('md5');
md5.update(data, 'utf8');
return md5.digest('hex');
}
function makeSign(url, date, bucket, operator, password){
// var uri = url.join('\n');
var sign = url + '&' + bucket + '&' + date + '&' + md5sum(password);
console.log(sign);
return 'UpYun ' + bucket + ':' +operator + ':' + md5sum(sign);
}
function refresh(url, bucket, operator, password) {
var urls = url.join('\n');
var date = new Date().toGMTString();
var sign = makeSign(urls, date, bucket, operator, password)
console.log('heads sign: ', sign);
console.log('url;', urls);
var query = {
url: UPYUN_CACHE,
headers: {
'Authorization': sign,
'Date': date,
'EXPECT': ''
},
form: {
purge: urls
}
}
request.post(query, function (err, res, body) {
console.log(body);
});
}
var _operator = 'wanclient';
var _password = 'xx';
var _bucket = 'wan-image';
var URL = ['http://huiyuan-wantest.bigertech.com/index?text=aaaa'];
refresh(URL, _bucket, _operator, _password);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment