Skip to content

Commit

Permalink
chore: remove comments, modify .gitignore and add case for url encode (
Browse files Browse the repository at this point in the history
…ali-sdk#491)

* chore: remove comments, modify .gitignore and add case for url encode

* chore: build dist/ and eslint
  • Loading branch information
luozhang002 authored and binghaiwang committed Jun 20, 2018
1 parent 1df7d41 commit e651667
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test/node/.tmp
test/browser/.tmp
test/demo.js
yarn.lock
package-lock.json

# Ide
.idea/
Expand Down
1 change: 0 additions & 1 deletion dist/aliyun-oss-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ proto._getReqUrl = function _getReqUrl(params) {

ep.query = query;

// As '%20' is not recognized by OSS server, we must convert it to '+'.
return urlutil.format(ep);
};

Expand Down
1 change: 0 additions & 1 deletion lib/browser/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ proto._getReqUrl = function _getReqUrl(params) {

ep.query = query;

// As '%20' is not recognized by OSS server, we must convert it to '+'.
return urlutil.format(ep);
};

Expand Down
44 changes: 22 additions & 22 deletions lib/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,35 @@ proto.getBucket = function getBucket() {
};

proto.getBucketLocation = function* getBucketLocation(name, region, options) {
name = name || this.getBucket();
const params = this._bucketRequestParams('GET', name, 'location', options);
params.successStatuses = [200];
params.xmlResponse = true;
const result = yield this.request(params);
return {
location:result.data,
res: result.res,
};
}
name = name || this.getBucket();
const params = this._bucketRequestParams('GET', name, 'location', options);
params.successStatuses = [200];
params.xmlResponse = true;
const result = yield this.request(params);
return {
location: result.data,
res: result.res,
};
};

proto.getBucketInfo = function* getBucketInfo(name, region, options) {
name = name || this.getBucket();
const params = this._bucketRequestParams('GET', name, 'bucketInfo', options);
params.successStatuses = [200];
params.xmlResponse = true;
const result = yield this.request(params);
return {
bucket: result.data.Bucket,
res: result.res,
};
}
name = name || this.getBucket();
const params = this._bucketRequestParams('GET', name, 'bucketInfo', options);
params.successStatuses = [200];
params.xmlResponse = true;
const result = yield this.request(params);
return {
bucket: result.data.Bucket,
res: result.res,
};
};

proto.putBucket = function* putBucket(name, region, options) {
options = options || {};
const params = this._bucketRequestParams('PUT', name, '', options);

const startTag = '<?xml version="1.0" encoding="UTF-8"?>\n<CreateBucketConfiguration>'
const endTag = '</CreateBucketConfiguration>'
const startTag = '<?xml version="1.0" encoding="UTF-8"?>\n<CreateBucketConfiguration>';
const endTag = '</CreateBucketConfiguration>';
let paramlXML = '';

// server not support
Expand Down
1 change: 0 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ proto._getReqUrl = function _getReqUrl(params) {

ep.query = query;

// As '%20' is not recognized by OSS server, we must convert it to '+'.
return urlutil.format(ep);
};

Expand Down
39 changes: 19 additions & 20 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ describe('test/bucket.test.js', () => {
});

describe('getBucketInfo', () => {
it("it should return correct bucketInfo when bucket exist", function* () {
let regionInteranl = `${this.region}-interanl`
it('it should return correct bucketInfo when bucket exist', function* () {
const result = yield this.store.getBucketInfo(this.bucket);
assert.equal(result.res.status, 200);

Expand All @@ -99,27 +98,27 @@ describe('test/bucket.test.js', () => {
assert.equal(result.bucket.IntranetEndpoint, `${this.region}-internal.aliyuncs.com`);
assert.equal(result.bucket.AccessControlList.Grant, 'private');
assert.equal(result.bucket.StorageClass, 'Standard');
})
});

it("it should return NoSuchBucketError when bucket not exist", function* () {
yield utils.throws(function* () {
yield this.store.getBucketInfo('not-exists-bucket');
}.bind(this), 'NoSuchBucketError');
})
})
it('it should return NoSuchBucketError when bucket not exist', function* () {
yield utils.throws(function* () {
yield this.store.getBucketInfo('not-exists-bucket');
}.bind(this), 'NoSuchBucketError');
});
});

describe('getBucketLoaction', () => {
it("it should return loaction this.region", function* () {
const result = yield this.store.getBucketLocation(this.bucket);
assert.equal(result.location, this.region);
})

it("it should return NoSuchBucketError when bucket not exist", function* () {
yield utils.throws(function* () {
yield this.store.getBucketLocation('not-exists-bucket');
}.bind(this), 'NoSuchBucketError');
})
})
it('it should return loaction this.region', function* () {
const result = yield this.store.getBucketLocation(this.bucket);
assert.equal(result.location, this.region);
});

it('it should return NoSuchBucketError when bucket not exist', function* () {
yield utils.throws(function* () {
yield this.store.getBucketLocation('not-exists-bucket');
}.bind(this), 'NoSuchBucketError');
});
});

describe('deleteBucket()', () => {
it('should delete not exists bucket throw NoSuchBucketError', function* () {
Expand Down
17 changes: 16 additions & 1 deletion test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const copy = require('copy-to');
const mm = require('mm');
const streamEqual = require('stream-equal');
const crypto = require('crypto');
const urlutil = require('url')
const urlutil = require('url');

const tmpdir = path.join(__dirname, '.tmp');
if (!fs.existsSync(tmpdir)) {
Expand Down Expand Up @@ -289,6 +289,21 @@ describe('test/object.test.js', () => {
const info = yield this.store.head(name);
assert.equal(info.res.headers['content-type'], 'application/javascript; charset=utf8');
});

it('should return correct encode when name include + and space', function* () {
const name = 'ali-sdkhahhhh+oss+mm xxx.js';
const object = yield this.store.put(name, __filename, {
headers: {
'Content-Type': 'text/plain; charset=gbk',
},
});
assert(object.name, name);
const info = yield this.store.head(name);
const url = info.res.requestUrls[0];
const { pathname } = urlutil.parse(url)
assert.equal(pathname, '/ali-sdkhahhhh%2Boss%2Bmm%20xxx.js');
assert.equal(info.res.headers['content-type'], 'text/plain; charset=gbk');
});
});

describe('mimetype', () => {
Expand Down

0 comments on commit e651667

Please sign in to comment.