Skip to content

Commit

Permalink
check upload options
Browse files Browse the repository at this point in the history
  • Loading branch information
ymyang committed Mar 5, 2016
1 parent 6bfb61e commit fdce054
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
32 changes: 13 additions & 19 deletions lib/fdfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,6 @@ function _normalizeUploadParams(file, options) {
return;
}

if (is.string(file)) {
fs.stat(file, function(err, stats) {
if (err || !stats) {
reject(new Error('File [' + file + '] is not exists!'));
return;
}

options.size = stats.size;
if (!options.ext) {
options.ext = path.extname(file);
if (options.ext) {
// 去掉.
options.ext = options.ext.substring(1);
}
}
resolve();
});
return;
}

if (is.readableStream(file) && !options.size) {
reject(new Error('when the "file" parameter\'s is ReadableStream, options.size must specified'));
Expand Down Expand Up @@ -348,6 +329,19 @@ function _normalizeUploadParams(file, options) {
reject(new Error('options.offset must be a number'));
}
}

if (is.string(file)) {
var stats = fs.statSync(file);
options.size = stats.size;
if (!options.ext) {
options.ext = path.extname(file);
if (options.ext) {
// 去掉.
options.ext = options.ext.substring(1);
}
}
resolve();
}
resolve();
});

Expand Down
4 changes: 1 addition & 3 deletions lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,8 @@ Storage.prototype.upload = function(file, options) {
return this._appendFile(file, options);
} else if (options.method === protocol.FDFS_METHOD_MODIFY_FILE) {
return this._modifyFile(file, options);
} else {
var err = new Error("options.method must in ['upload', 'uploadAppender', 'append', 'modify'] ");
throw err;
}
return Promise.reject(new Error("options.method must in ['upload', 'uploadAppender', 'append', 'modify'] "));
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fdfs",
"version": "0.9.0",
"version": "0.9.1",
"description": "FastDFS node client",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/FdfsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var FdfsClient = require('../index.js');
var fdfs = new FdfsClient({
trackers: [
{
host: '192.168.0.11',
host: '192.168.0.120',
port: 22122
},
{
Expand Down

0 comments on commit fdce054

Please sign in to comment.