Skip to content

Commit d92ff29

Browse files
committed
0.4: Support config signature and policy by manual
1 parent 81ec608 commit d92ff29

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

bower.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "upyun",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"authors": [
55
"turing <[email protected]>"
66
],
77
"description": "a pure front-end upyun form upload service, supports both native js and angular.js",
8-
"main": "src/upyun.js",
8+
"main": "dist/upyun.min.js",
99
"keywords": [
1010
"upyun",
1111
"angular.js",
@@ -25,9 +25,7 @@
2525
"dependencies": {
2626
"angular": "*",
2727
"angular-base64": "~2.0.2",
28-
"angular-md5": "~0.1.7"
29-
},
30-
"devDependencies": {
28+
"angular-md5": "~0.1.7",
3129
"js-base64": "2.1.5",
3230
"js-md5": "1.1.0"
3331
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "upyun-form",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "a pure front-end upyun form upload service, supports both native js and angular.js",
55
"main": "src/upyun.js",
66
"directories": {

src/upyun.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
;(function(window, angular, NProgress) {
22
'use strict';
33
var NProgressExist = NProgress && NProgress.start && NProgress.done;
4+
var toplevelList = ['signature', 'form_api_secret', 'endpoint', 'host'];
45

56
// Inject as a angular module
67
if (angular) {
@@ -22,9 +23,8 @@
2223
}
2324

2425
Upyun.prototype.set = function(k, v) {
25-
var toplevel = ['form_api_secret', 'endpoint', 'host'];
2626
if (k && v) {
27-
if (toplevel.indexOf(k) > -1)
27+
if (toplevelList.indexOf(k) > -1)
2828
this.configs[k] = v;
2929
else
3030
this.configs.params[k] = v;
@@ -64,15 +64,15 @@
6464
new FormData(document.forms.namedItem(params)) :
6565
new FormData();
6666

67-
var policy = self.base64.encode(JSON.stringify(self.configs.params));
67+
var policy = self.configs.policy || self.base64.encode(JSON.stringify(self.configs.params));
6868
var apiendpoint = self.configs.endpoint || 'http://v0.api.upyun.com/' + self.configs.params.bucket;
6969
var imageHost = self.configs.host || 'http://' + self.configs.params.bucket + '.b0.upaiyun.com';
7070

7171
// by default, if not upload files by form,
7272
// file object will be parse as `params`
7373
if (!uploadByForm) data.append('file', params);
7474
data.append('policy', policy);
75-
data.append('signature', md5hash(policy + '&' + self.configs.form_api_secret));
75+
data.append('signature', self.configs.signature || md5hash(policy + '&' + self.configs.form_api_secret));
7676

7777
// open request
7878
req.open('POST', apiendpoint, true);
@@ -120,9 +120,8 @@
120120
this.config = function(configs) {
121121
if (!configs || !angular.isObject(configs))
122122
return;
123-
var toplevel = ['form_api_secret', 'endpoint', 'host'];
124123
angular.forEach(configs, function(v, k) {
125-
if (toplevel.indexOf(k) > -1)
124+
if (toplevelList.indexOf(k) > -1)
126125
self.configs[k] = v;
127126
else
128127
self.configs.params[k] = v;

0 commit comments

Comments
 (0)