Skip to content

detect up.getOption before using it #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions demo/js/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function QiniuJsSDK() {
// qiniu service max_chunk_size is 4m
// reset chunk_size to max_chunk_size(4m) when chunk_size > 4m
}
}
};
reset_chunk_size();

var getUpToken = function() {
Expand All @@ -284,9 +284,12 @@ function QiniuJsSDK() {
};

var getFileKey = function(up, file, func) {
var key = '';
var key = '',
unique_names = false;
if (!op.save_key) {
if (up.getOption('unique_names')) {
unique_names = up.getOption && up.getOption('unique_names');
unique_names = unique_names || (up.settings && up.settings.unique_names);
if (unique_names) {
var ext = that.getFileExtension(file.name);
key = ext ? file.id + '.' + ext : file.id;
} else if (typeof func === 'function') {
Expand All @@ -313,7 +316,9 @@ function QiniuJsSDK() {
uploader.init();

uploader.bind('FilesAdded', function(up, files) {
if (up.getOption('auto_start')) {
var auto_start = up.getOption && up.getOption('auto_start');
auto_start = auto_start || (up.settings && up.settings.auto_start);
if (auto_start) {
$.each(files, function(i, file) {
up.start();
});
Expand Down Expand Up @@ -348,7 +353,8 @@ function QiniuJsSDK() {
};


var chunk_size = up.getOption('chunk_size');
var chunk_size = up.getOption && up.getOption('chunk_size');
chunk_size = chunk_size || (up.settings && up.settings.chunk_size);

if (uploader.runtime === 'html5' && chunk_size) {
if (file.size < chunk_size) {
Expand Down Expand Up @@ -376,7 +382,8 @@ function QiniuJsSDK() {

ctx = ctx ? ctx + ',' + res.ctx : res.ctx;
var leftSize = info.total - info.offset;
var chunk_size = up.getOption('chunk_size');
var chunk_size = up.getOption && up.getOption('chunk_size');
chunk_size = chunk_size || (up.settings && up.settings.chunk_size);
if (leftSize < chunk_size) {
up.setOption({
'url': 'http://up.qiniu.com/mkblk/' + leftSize
Expand All @@ -395,7 +402,9 @@ function QiniuJsSDK() {
errTip = '上传失败。请稍后再试。';
break;
case plupload.FILE_SIZE_ERROR:
errTip = '浏览器最大可上传' + up.getOption('max_file_size') + '。更大文件请使用命令行工具。';
var max_file_size = up.getOption && up.getOption('max_file_size');
max_file_size = max_file_size || (up.settings && up.settings.max_file_size);
errTip = '浏览器最大可上传' + max_file_size + '。更大文件请使用命令行工具。';
break;
case plupload.FILE_EXTENSION_ERROR:
errTip = '文件验证失败。请稍后重试。';
Expand Down Expand Up @@ -720,4 +729,4 @@ function QiniuJsSDK() {

}

var Qiniu = new QiniuJsSDK();
var Qiniu = new QiniuJsSDK();
25 changes: 17 additions & 8 deletions src/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function QiniuJsSDK() {
// qiniu service max_chunk_size is 4m
// reset chunk_size to max_chunk_size(4m) when chunk_size > 4m
}
}
};
reset_chunk_size();

var getUpToken = function() {
Expand All @@ -284,9 +284,12 @@ function QiniuJsSDK() {
};

var getFileKey = function(up, file, func) {
var key = '';
var key = '',
unique_names = false;
if (!op.save_key) {
if (up.getOption('unique_names')) {
unique_names = up.getOption && up.getOption('unique_names');
unique_names = unique_names || (up.settings && up.settings.unique_names);
if (unique_names) {
var ext = that.getFileExtension(file.name);
key = ext ? file.id + '.' + ext : file.id;
} else if (typeof func === 'function') {
Expand All @@ -313,7 +316,9 @@ function QiniuJsSDK() {
uploader.init();

uploader.bind('FilesAdded', function(up, files) {
if (up.getOption('auto_start')) {
var auto_start = up.getOption && up.getOption('auto_start');
auto_start = auto_start || (up.settings && up.settings.auto_start);
if (auto_start) {
$.each(files, function(i, file) {
up.start();
});
Expand Down Expand Up @@ -348,7 +353,8 @@ function QiniuJsSDK() {
};


var chunk_size = up.getOption('chunk_size');
var chunk_size = up.getOption && up.getOption('chunk_size');
chunk_size = chunk_size || (up.settings && up.settings.chunk_size);

if (uploader.runtime === 'html5' && chunk_size) {
if (file.size < chunk_size) {
Expand Down Expand Up @@ -376,7 +382,8 @@ function QiniuJsSDK() {

ctx = ctx ? ctx + ',' + res.ctx : res.ctx;
var leftSize = info.total - info.offset;
var chunk_size = up.getOption('chunk_size');
var chunk_size = up.getOption && up.getOption('chunk_size');
chunk_size = chunk_size || (up.settings && up.settings.chunk_size);
if (leftSize < chunk_size) {
up.setOption({
'url': 'http://up.qiniu.com/mkblk/' + leftSize
Expand All @@ -395,7 +402,9 @@ function QiniuJsSDK() {
errTip = '上传失败。请稍后再试。';
break;
case plupload.FILE_SIZE_ERROR:
errTip = '浏览器最大可上传' + up.getOption('max_file_size') + '。更大文件请使用命令行工具。';
var max_file_size = up.getOption && up.getOption('max_file_size');
max_file_size = max_file_size || (up.settings && up.settings.max_file_size);
errTip = '浏览器最大可上传' + max_file_size + '。更大文件请使用命令行工具。';
break;
case plupload.FILE_EXTENSION_ERROR:
errTip = '文件验证失败。请稍后重试。';
Expand Down Expand Up @@ -720,4 +729,4 @@ function QiniuJsSDK() {

}

var Qiniu = new QiniuJsSDK();
var Qiniu = new QiniuJsSDK();