-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
56 lines (43 loc) · 1.42 KB
/
index.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
'use strict';
var crypto = require('crypto');
var util = require('util');
var request = require('request');
function UpYunAV(bucket_name, operator_name, password) {
this._bucket_name = bucket_name;
this._operator_name = operator_name;
this._password = crypto.createHash('md5').update(password).digest('hex');
}
UpYunAV.prototype.pretreatment = function(source, params, callback) {
params.source = source;
this._doRequest('/pretreatment/', 'POST', params, callback);
};
UpYunAV.prototype._doRequest = function(path, method, params, callback) {
var autheader = util.format('UPYUN %s:%s', this._operator_name, this._makeSign(params));
function doit() {
request({
url: 'http://p0.api.upyun.com' + path,
method: method,
headers: {
'Authorization': autheader
},
form: params
}, function(err, res, body) {
callback(err, body);
});
}
doit();
};
UpYunAV.prototype._makeSign = function(params) {
var policy_string = Object.keys(params).sort().map(function(key) {
if (key === 'signature') {
return '';
}
return key + params[key];
}).join('');
policy_string = util.format(
'%s%s%s',
this._operator_name,
policy_string, this._password);
return crypto.createHash('md5').update(policy_string).digest('hex');
};
module.exports = UpYunAV;