Skip to content

Commit

Permalink
Merge db48fa7 into aec602d
Browse files Browse the repository at this point in the history
  • Loading branch information
sabakugaara committed Oct 30, 2015
2 parents aec602d + db48fa7 commit 8959383
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,27 @@ UPYUN.prototype.uploadFile = function(remotePath, localFile, type, checksum, opt
}
callback = arguments[arguments.length - 1];
var isFile = fs.existsSync(localFile);
if(!isFile) {
throw new Error('file path not exists: ' + localFile);
}

var _self = this;
opts = opts || {};

// TODO: default type
opts['Content-Type'] = type;
var contentLength = isFile ? fs.statSync(localFile).size : localFile.length;
var contentLength = fs.statSync(localFile).size;
checksum = arguments.length > 4 && typeof checksum !== 'function' ? checksum : true;

// TODO: optimize logical
if (typeof checksum === 'string') {
contentLength = isFile ? fs.statSync(localFile).size : localFile.length;
opts['Content-MD5'] = checksum;
_upload(contentLength, opts);
} else if (checksum === true){
if (isFile) {
utils.md5sumFile(localFile, function(err, result) {
opts['Content-MD5'] = result;
_upload(contentLength, opts);
});
} else {
opts['Content-MD5'] = utils.md5sum(localFile);
_upload(contentLength, opts);
}
} else {
_upload(contentLength, opts);
}
Expand Down
20 changes: 0 additions & 20 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,6 @@ describe('REST API: ', function() {
});
});

it('should accept string', function(done) {
upyun.uploadFile(remoteDir + '/' + fileName, 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id molestias ut quisquam, dolores blanditiis nobis labore eum, accusantium dolorem laboriosam est modi sit quam libero aliquam nam corporis nihil rerum.', 'text/plain', true, function(err, result) {
if(err) {
throw err;
}
result.statusCode.should.be.exactly(200);
done();
});
});

it('should accept string and ignore checksum', function(done) {
upyun.uploadFile(remoteDir + '/' + fileName, 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id molestias ut quisquam, dolores blanditiis nobis labore eum, accusantium dolorem laboriosam est modi sit quam libero aliquam nam corporis nihil rerum.', 'text/plain', false, function(err, result) {
if(err) {
throw err;
}
result.statusCode.should.be.exactly(200);
done();
});
});

})


Expand Down

0 comments on commit 8959383

Please sign in to comment.