Skip to content

Commit

Permalink
重构一下目录结构
Browse files Browse the repository at this point in the history
  • Loading branch information
leeight committed May 27, 2015
1 parent 8a84abd commit f8f7f92
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
baidubce-sdk.bundle.js
18 changes: 10 additions & 8 deletions src/bos_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ BosClient.prototype.putObjectFromDataUrl = function (bucketName, key, data, opti

var headers = {};
headers[H.CONTENT_LENGTH] = data.length;
headers[H.CONTENT_MD5] = require('./crypto').md5sum(data);
// 对于浏览器调用API的时候,默认不添加 H.CONTENT_MD5 字段,因为计算起来比较慢
// headers[H.CONTENT_MD5] = require('./crypto').md5sum(data);
options = u.extend(headers, options);

return this.putObject(bucketName, key, data, options);
Expand Down Expand Up @@ -379,7 +380,8 @@ BosClient.prototype.uploadPartFromDataUrl = function (bucketName, key, uploadId,
var headers = {};
headers[H.CONTENT_LENGTH] = partSize;
headers[H.CONTENT_TYPE] = 'application/octet-stream';
headers[H.CONTENT_MD5] = require('./crypto').md5sum(data);
// 对于浏览器调用API的时候,默认不添加 H.CONTENT_MD5 字段,因为计算起来比较慢
// headers[H.CONTENT_MD5] = require('./crypto').md5sum(data);

options = this._checkOptions(u.extend(headers, options));
return this._sendRequest('PUT', {
Expand Down Expand Up @@ -515,12 +517,12 @@ BosClient.prototype._checkOptions = function (options, allowedParams) {

BosClient.prototype._prepareObjectHeaders = function (options) {
var allowedHeaders = [
'Content-Length',
'Content-Encoding',
'Content-MD5',
'Content-Type',
'Content-Disposition',
'ETag'
H.CONTENT_LENGTH,
H.CONTENT_ENCODING,
H.CONTENT_MD5,
H.CONTENT_TYPE,
H.CONTENT_DISPOSITION,
H.ETAG
];
var metaSize = 0;
var headers = u.pick(options, function (value, key) {
Expand Down
3 changes: 3 additions & 0 deletions src/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
exports.CONTENT_TYPE = 'Content-Type';
exports.CONTENT_LENGTH = 'Content-Length';
exports.CONTENT_MD5 = 'Content-MD5';
exports.CONTENT_ENCODING = 'Content-Encoding';
exports.CONTENT_DISPOSITION = 'Content-Disposition';
exports.ETAG = 'ETag';
exports.CONNECTION = 'Connection';
exports.HOST = 'Host';
exports.USER_AGENT = 'User-Agent';
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
all:
../node_modules/.bin/jasmine-node --verbose --growl --captureExceptions .
../node_modules/.bin/jasmine-node --verbose --growl --captureExceptions sdk
2 changes: 1 addition & 1 deletion test/auth.spec.js → test/sdk/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* specific language governing permissions and limitations under the License.
*/

var Auth = require('../src/auth');
var Auth = require('../../src/auth');

describe('Auth', function() {
it('queryStringCanonicalization', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/bos_client.spec.js → test/sdk/bos_client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var fs = require('fs');
var Q = require('q');
var u = require('underscore');

var config = require('./config');
var BosClient = require('../src/bos_client');
var config = require('../config');
var BosClient = require('../../src/bos_client');

describe('BosClient', function() {
var client;
Expand Down
6 changes: 3 additions & 3 deletions test/crypto.spec.js → test/sdk/crypto.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

var path = require('path');

var crypto = require('../src/crypto');
var crypto = require('../../src/crypto');

describe('crypto', function() {
it('md5sum', function() {
expect(crypto.md5sum('hello world')).toEqual('XrY7u+Ae7tCTyyK7j1rNww==');
});

it('md5file', function(done) {
crypto.md5file(path.join(__dirname, 'Makefile'))
crypto.md5file(path.join(__dirname, '..', 'Makefile'))
.then(function(md5sum) {
expect(md5sum).toEqual('58KGo4t3osBDuVpJOXeIjw==');
expect(md5sum).toEqual('B89a9ZnS6TfU5EE82PwKKA==');
})
.fin(done);
});
Expand Down
16 changes: 8 additions & 8 deletions test/http_client.spec.js → test/sdk/http_client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* specific language governing permissions and limitations under the License.
*/

var Auth = require('../src/auth');
var HttpClient = require('../src/http_client');
var WMStream = require('../src/wm_stream');
var Auth = require('../../src/auth');
var HttpClient = require('../../src/http_client');
var WMStream = require('../../src/wm_stream');

function sign_function(credentials, http_method, path, params, headers) {
var auth = new Auth(credentials.ak, credentials.sk);
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('HttpClient', function() {
it('sendRequest', function(done) {
var fail = this.fail.bind(this);

var config = require('./config');
var config = require('../config');
var client = new HttpClient(config);

client.sendRequest('GET', '/v1', null, null, null, sign_function)
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('HttpClient', function() {
// Prepare the request body
var body = new Buffer(JSON.stringify({accessControlList: grant_list}));

var config = require('./config');
var config = require('../config');
var client = new HttpClient(config);
var path = '/v1/' + bucket;

Expand Down Expand Up @@ -160,7 +160,7 @@ describe('HttpClient', function() {
// Prepare the request body
var body = JSON.stringify({accessControlList: grant_list});

var config = require('./config');
var config = require('../config');
var client = new HttpClient(config);
var path = '/v1/' + bucket;

Expand Down Expand Up @@ -213,7 +213,7 @@ describe('HttpClient', function() {
body.push(access_control_list);
body.push(null);

var config = require('./config');
var config = require('../config');
var client = new HttpClient(config);
var path = '/v1/' + bucket;

Expand Down Expand Up @@ -249,7 +249,7 @@ describe('HttpClient', function() {
it('sendRequestWithOutputStream', function(done) {
var fail = this.fail.bind(this);

var config = require('./config');
var config = require('../config');
var client = new HttpClient(config);

var output_stream = new WMStream();
Expand Down
4 changes: 2 additions & 2 deletions test/media_client.spec.js → test/sdk/media_client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var u = require('underscore');
var debug = require('debug')('media_client');

var MediaClient = require('../src/media_client');
var MediaClient = require('../../src/media_client');

describe('MediaClient', function () {
var client;
Expand All @@ -24,7 +24,7 @@ describe('MediaClient', function () {
return this.fail.call(this, JSON.stringify(arguments));
}, this);

client = new MediaClient(require('./media.config'));
client = new MediaClient(require('../media.config'));
});

afterEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/mime.types.spec.js → test/sdk/mime.types.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* specific language governing permissions and limitations under the License.
*/

var MimeType = require('../src/mime.types');
var MimeType = require('../../src/mime.types');

describe('MimeType', function() {
it('guess', function() {
Expand Down

0 comments on commit f8f7f92

Please sign in to comment.