Skip to content

Commit 4f0a7a7

Browse files
committed
Merge pull request #136 from qiniu/develop
release 6.1.6
2 parents 6ba08ce + b711636 commit 4f0a7a7

File tree

10 files changed

+75
-74
lines changed

10 files changed

+75
-74
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## CHANGE LOG
22

3+
### v6.1.6
4+
5+
2014-10-31
6+
7+
- 增加fsizelimit, insertonly
8+
9+
310
### v6.1.5
411

512
2014-7-23 issue [#111](https://github.com/qiniu/nodejs-sdk/pull/111)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $ npm install qiniu
4141

4242
## 许可证
4343

44-
Copyright (c) 2013 qiniu.com
44+
Copyright (c) 2014 qiniu.com
4545

4646
基于 MIT 协议发布:
4747

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ func pfop(bucketName, keyName, fops, opts, callback);
540540
541541
// 例子
542542
// pfop
543-
qiniu.fop.pfop(TEST_BUCKET, keys[0], 'avinfo', {notifyUrl: 'www.test.com', force: true}, function(err, ret) {
543+
qiniu.fop.pfop(TEST_BUCKET, keys[0], 'avinfo', {notifyURL: 'www.test.com', force: true}, function(err, ret) {
544544
ret.should.have.keys('persistentId');
545545
done();
546546
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qiniu",
3-
"version": "6.1.5",
3+
"version": "6.1.6",
44
"description": "Node wrapper for Qiniu Resource (Cloud) Storage API",
55
"main": "index.js",
66
"directories": {

qiniu/conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports.ACCESS_KEY = '<PLEASE APPLY YOUR ACCESS KEY>';
66
exports.SECRET_KEY = '<DONT SEND YOUR SECRET KEY TO ANYONE>';
77

88
var pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../', 'package.json')));
9-
var ua = function(){
9+
var ua = function() {
1010
return 'QiniuNodejs/' + pkg.version + ' (' + os.type() + '; ' + os.platform() + '; ' + os.arch() + '; )';
1111
}
1212

@@ -15,4 +15,5 @@ exports.USER_AGENT = ua();
1515
exports.UP_HOST = 'http://upload.qiniu.com';
1616
exports.RS_HOST = 'http://rs.qbox.me';
1717
exports.RSF_HOST = 'http://rsf.qbox.me';
18+
exports.API_HOST = 'http://api.qiniu.com';
1819
exports.RPC_TIMEOUT = 3600000; // default rpc timeout: one hour

qiniu/fop.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var util = require('./util');
22
var rpc = require('./rpc');
3+
var conf = require('./conf');
34

45
var querystring = require('querystring');
56

@@ -17,7 +18,7 @@ function ImageView(mode, width, height, quality, format) {
1718
}
1819

1920
ImageView.prototype.makeRequest = function(url) {
20-
url += '?imageView/' + this.mode;
21+
url += '?imageView2/' + this.mode;
2122

2223
if (this.width > 0) {
2324
url += '/w/' + this.width;
@@ -38,15 +39,13 @@ ImageView.prototype.makeRequest = function(url) {
3839
return url;
3940
}
4041

41-
function ImageInfo() {
42-
}
42+
function ImageInfo() {}
4343

4444
ImageInfo.prototype.makeRequest = function(url) {
4545
return url + '?imageInfo'
4646
}
4747

48-
function Exif() {
49-
}
48+
function Exif() {}
5049

5150
Exif.prototype.makeRequest = function(url) {
5251
return url + '?exif'
@@ -70,10 +69,12 @@ function pfop(bucket, key, fops, opts, onret) {
7069
if (opts.force) {
7170
param.force = 1;
7271
}
72+
if (opts.pipeline) {
73+
param.pipeline = opts.pipeline;
74+
}
7375

74-
var uri = 'http://api.qiniu.com/pfop/';
76+
var uri = conf.API_HOST + '/pfop/';
7577
var body = querystring.stringify(param);
7678
var auth = util.generateAccessToken(uri, body);
7779
rpc.postWithForm(uri, body, auth, onret);
7880
}
79-

qiniu/rs.js

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var url = require('url');
32
var crypto = require('crypto');
43
var formstream = require('formstream');
@@ -58,6 +57,13 @@ Client.prototype.copy = function(bucketSrc, keySrc, bucketDest, keyDest, onret)
5857
rpc.postWithoutForm(uri, digest, onret);
5958
}
6059

60+
Client.prototype.fetch = function(url, bucket, key, onret) {
61+
var bucketUri = getEncodedEntryUri(bucket, key);
62+
var fetchUrl = util.urlsafeBase64Encode(url);
63+
var uri = 'http://iovip.qbox.me/fetch/' + fetchUrl + '/to/' + bucketUri;
64+
var digest = util.generateAccessToken(uri, null);
65+
rpc.postWithoutForm(uri, digest, onret);
66+
}
6167

6268
function Entry(hash, fsize, putTime, mimeType, endUser) {
6369
this.hash = hash || null;
@@ -135,17 +141,35 @@ function getEncodedEntryUri(bucket, key) {
135141

136142
// ----- token --------
137143
// @gist PutPolicy
138-
function PutPolicy(scope, callbackUrl, callbackBody, returnUrl, returnBody,
139-
asyncOps, endUser, expires, persistentOps, persistentNotifyUrl) {
140-
this.scope = scope || null;
141-
this.callbackUrl = callbackUrl || null;
142-
this.callbackBody = callbackBody || null;
143-
this.returnUrl = returnUrl || null;
144-
this.returnBody = returnBody || null;
145-
this.endUser = endUser || null;
146-
this.expires = expires || 3600;
147-
this.persistentOps = persistentOps || null;
148-
this.persistentNotifyUrl = persistentNotifyUrl || null;
144+
function PutPolicy(putPolicyObj) {
145+
146+
if (typeof putPolicyObj !== 'object') {
147+
return false;
148+
}
149+
150+
this.scope = putPolicyObj.scope || null;
151+
this.expires = putPolicyObj.expires || 3600;
152+
this.insertOnly = putPolicyObj.insertOnly || null;
153+
154+
this.saveKey = putPolicyObj.saveKey || null;
155+
this.endUser = putPolicyObj.endUser || null;
156+
157+
this.returnUrl = putPolicyObj.returnUrl || null;
158+
this.returnBody = putPolicyObj.returnBody || null;
159+
160+
this.callbackUrl = putPolicyObj.callbackUrl || null;
161+
this.callbackHost = putPolicyObj.callbackHost || null;
162+
this.callbackBody = putPolicyObj.callbackBody || null;
163+
164+
this.persistentOps = putPolicyObj.persistentOps || null;
165+
this.persistentNotifyUrl = putPolicyObj.persistentNotifyUrl || null;
166+
this.persistentPipeline = putPolicyObj.persistentPipeline || null;
167+
168+
this.fsizeLimit = putPolicyObj.fsizeLimit || null;
169+
170+
this.detectMime = putPolicyObj.detectMime || null;
171+
172+
this.mimeLimit = putPolicyObj.mimeLimit || null;
149173
}
150174
// @endgist
151175

@@ -161,54 +185,18 @@ PutPolicy.prototype.token = function(mac) {
161185
return uploadToken;
162186
}
163187

164-
PutPolicy.prototype.getFlags = function(putPolicy) {
188+
PutPolicy.prototype.getFlags = function() {
165189
var flags = {};
166-
if (this.scope != null) {
167-
flags['scope'] = this.scope;
168-
}
169-
if (this.callbackUrl != null) {
170-
flags['callbackUrl'] = this.callbackUrl;
171-
}
172-
if (this.callbackBody != null) {
173-
flags['callbackBody'] = this.callbackBody;
174-
}
175-
if (this.returnUrl != null) {
176-
flags['returnUrl'] = this.returnUrl;
177-
}
178-
if (this.returnBody != null) {
179-
flags['returnBody'] = this.returnBody;
180-
}
181-
if (this.endUser != null) {
182-
flags['endUser'] = this.endUser;
183-
}
184-
if (this.persistentOps != null) {
185-
flags['persistentOps'] = this.persistentOps;
186-
}
187-
if (this.persistentNotifyUrl != null) {
188-
flags['persistentNotifyUrl'] = this.persistentNotifyUrl;
189-
}
190-
if (this.persistentPipeline != null) {
191-
flags['persistentPipeline'] = this.persistentPipeline;
192-
}
193-
if (this.mimeLimit != null) {
194-
flags['mimeLimit'] = this.mimeLimit;
195-
}
196-
if (this.insertOnly != null) {
197-
flags['insertOnly'] = this.insertOnly;
198-
}
199-
if (this.detectMime != null) {
200-
flags['detectMime'] = this.detectMime;
201-
}
202-
if (this.saveKey != null) {
203-
flags['saveKey'] = this.saveKey;
190+
var attrs = ['scope', 'insertOnly', 'saveKey', 'endUser', 'returnUrl', 'returnBody', 'callbackUrl', 'callbackHost', 'callbackBody', 'callbackBodyType', 'callbackFetchKey', 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', 'fsizeLimit', 'detectMime', 'mimeLimit'];
191+
192+
for (var i = attrs.length - 1; i >= 0; i--) {
193+
if (this[attrs[i]] !== null) {
194+
flags[attrs[i]] = this[attrs[i]];
195+
}
204196
}
197+
205198
flags['deadline'] = this.expires + Math.floor(Date.now() / 1000);
206-
if (this.fsizeLimit != null) {
207-
flags['fsizeLimit'] = this.fsizeLimit;
208-
}
209-
if (this.insertOnly != null) {
210-
flags['insertOnly'] = this.insertOnly;
211-
}
199+
212200
return flags;
213201
}
214202

@@ -239,5 +227,5 @@ GetPolicy.prototype.makeRequest = function(baseUrl, mac) {
239227
// query like '-thumbnail', '?imageMogr2/thumbnail/960x' and so on
240228
function makeBaseUrl(domain, key, query) {
241229
key = new Buffer(key);
242-
return 'http://' + domain + '/' + querystring.escape(key) + (query||'');
230+
return 'http://' + domain + '/' + querystring.escape(key) + (query || '');
243231
}

test/fop.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ describe('test start step 0', function() {
1919
iv.height = 100;
2020
iv.width = 40;
2121
var returl = iv.makeRequest(pic);
22-
returl.should.equal(pic + '?imageView/1/w/40/h/100');
22+
returl.should.equal(pic + '?imageView2/1/w/40/h/100');
2323

2424
iv.quality = 20;
2525
iv.format = 'jpg';
2626
returl = iv.makeRequest(pic);
27-
returl.should.equal(pic + '?imageView/1/w/40/h/100/q/20/format/jpg');
27+
returl.should.equal(pic + '?imageView2/1/w/40/h/100/q/20/format/jpg');
2828
done();
2929
});
3030
});

test/io.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ describe('test start step1:', function() {
4444
describe('upload#', function() {
4545
var uptoken = null;
4646
beforeEach(function(done) {
47-
var putPolicy = new qiniu.rs.PutPolicy(TEST_BUCKET);
48-
uptoken = putPolicy.token();
47+
var putPolicy = new qiniu.rs.PutPolicy({
48+
scope: TEST_BUCKET
49+
});
50+
uptoken = putPolicy.token();
4951
done();
5052
});
5153

test/rs.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ describe('test start step2:', function() {
2525
describe('single file handle', function() {
2626

2727
before(function(done) {
28-
var putPolicy = new qiniu.rs.PutPolicy(TEST_BUCKET);
28+
var putPolicy = new qiniu.rs.PutPolicy({
29+
scope: TEST_BUCKET
30+
});
2931
var uptoken = putPolicy.token();
3032
qiniu.io.putFile(uptoken, logo2, imageFile, null, function(err, ret) {
3133
should.not.exist(err);

0 commit comments

Comments
 (0)