Skip to content

Commit 1417f1c

Browse files
committed
支持指定 Ip,增加 StrictSSL 参数
1 parent 56de8da commit 1417f1c

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

sdk/advance.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function sliceUploadFile(params, callback) {
144144
if (FileSize === 0) {
145145
params.Body = '';
146146
params.ContentLength = 0;
147-
params._OnlyUploadNotAddTask = true;
147+
params.SkipTask = true;
148148
self.putObject(params, function (err, data) {
149149
if (err) {
150150
return callback(err);
@@ -657,33 +657,38 @@ function uploadSliceItem(params, callback) {
657657
ContentLength = end - start;
658658
}
659659

660-
var PartItem = UploadData.PartList[PartNumber - 1];
661-
Async.retry(ChunkRetryTimes, function (tryCallback) {
662-
if (!self._isRunningTask(TaskId)) return;
663-
var Body = util.fileSlice(FilePath, start, end);
664-
self.multipartUpload({
665-
TaskId: TaskId,
666-
Bucket: Bucket,
667-
Region: Region,
668-
Key: Key,
669-
ContentLength: ContentLength,
670-
PartNumber: PartNumber,
671-
UploadId: UploadData.UploadId,
672-
ServerSideEncryption: ServerSideEncryption,
673-
Body: Body,
674-
onProgress: params.onProgress
660+
var md5Body = util.fileSlice(FilePath, start, end);
661+
util.getFileMd5(md5Body, function (err, md5) {
662+
var contentMd5 = md5 ? util.binaryBase64(md5) : '';
663+
var PartItem = UploadData.PartList[PartNumber - 1];
664+
Async.retry(ChunkRetryTimes, function (tryCallback) {
665+
if (!self._isRunningTask(TaskId)) return;
666+
var Body = util.fileSlice(FilePath, start, end);
667+
self.multipartUpload({
668+
TaskId: TaskId,
669+
Bucket: Bucket,
670+
Region: Region,
671+
Key: Key,
672+
ContentLength: ContentLength,
673+
PartNumber: PartNumber,
674+
UploadId: UploadData.UploadId,
675+
ServerSideEncryption: ServerSideEncryption,
676+
Body: Body,
677+
onProgress: params.onProgress,
678+
ContentMD5: contentMd5,
679+
}, function (err, data) {
680+
if (!self._isRunningTask(TaskId)) return;
681+
if (err) {
682+
return tryCallback(err);
683+
} else {
684+
PartItem.Uploaded = true;
685+
return tryCallback(null, data);
686+
}
687+
});
675688
}, function (err, data) {
676689
if (!self._isRunningTask(TaskId)) return;
677-
if (err) {
678-
return tryCallback(err);
679-
} else {
680-
PartItem.Uploaded = true;
681-
return tryCallback(null, data);
682-
}
690+
return callback(err, data);
683691
});
684-
}, function (err, data) {
685-
if (!self._isRunningTask(TaskId)) return;
686-
return callback(err, data);
687692
});
688693
}
689694

sdk/base.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,16 @@ function _submitRequest(params, callback) {
23802380
opt.headers && (opt.headers = util.clearKey(opt.headers));
23812381
opt = util.clearKey(opt);
23822382

2383+
var Ip = this.options.Ip;
2384+
if (Ip) {
2385+
opt.url = opt.url.replace(/^(https?:\/\/)([^\/]+)/, function (str, pre, Host) {
2386+
opt.headers.Host = Host;
2387+
return pre + Ip;
2388+
});
2389+
}
2390+
if (this.options.StrictSSL !== true) {
2391+
opt.strictSSL = this.options.StrictSSL;
2392+
}
23832393
if (this.options.Proxy) {
23842394
opt.proxy = this.options.Proxy;
23852395
}

sdk/cos.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var defaultOptions = {
3333
UploadCheckContentMd5: false,
3434
UploadIdCacheLimit: 500,
3535
Proxy: '',
36+
Ip: '',
37+
StrictSSL: true,
3638
UserAgent: '',
3739
};
3840

sdk/task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var originApiMap = {};
44
var transferToTaskMethod = function (apiMap, apiName) {
55
originApiMap[apiName] = apiMap[apiName];
66
apiMap[apiName] = function (params, callback) {
7-
if (params._OnlyUploadNotAddTask) {
7+
if (params.SkipTask) {
88
originApiMap[apiName].call(this, params, callback);
99
} else {
1010
this._addTask(apiName, params, callback);

sdk/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ util.getFileUUID = function (FileStat, ChunkSize) {
584584
util.getBodyMd5 = function (UploadCheckContentMd5, Body, callback) {
585585
callback = callback || noop;
586586
if (UploadCheckContentMd5) {
587-
if (Body instanceof Buffer || typeof Body.pipe !== 'function') {
587+
if (Body instanceof Buffer || typeof Body === 'string') {
588588
callback(util.md5(Body));
589589
} else {
590590
callback();

0 commit comments

Comments
 (0)