Skip to content

Commit 2ab0f59

Browse files
committed
Merge pull request #32 from qiniupd/11087_fix_offset_bug_when_reupload
11087 fix offset bug when reupload
2 parents 4f3dd49 + aa56620 commit 2ab0f59

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/qiniu.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,18 @@ function QiniuJsSDK() {
386386
var blockSize = chunk_size;
387387
if (localFileInfo) {
388388
localFileInfo = JSON.parse(localFileInfo);
389-
file.loaded = localFileInfo.offset;
390-
file.percent = localFileInfo.percent;
391-
ctx = localFileInfo.ctx;
392-
if (localFileInfo.offset + blockSize > file.size) {
393-
blockSize = file.size - localFileInfo.ctx;
389+
var now = (new Date()).getTime();
390+
var before = localFileInfo.time || 0;
391+
var aDay = 24 * 60 * 60 * 1000; // milliseconds
392+
if (now - before < aDay) {
393+
file.loaded = localFileInfo.offset;
394+
file.percent = localFileInfo.percent;
395+
ctx = localFileInfo.ctx;
396+
if (localFileInfo.offset + blockSize > file.size) {
397+
blockSize = file.size - localFileInfo.offset;
398+
}
399+
} else {
400+
localStorage.removeItem(file.name);
394401
}
395402
}
396403
up.setOption({
@@ -425,7 +432,8 @@ function QiniuJsSDK() {
425432
ctx: ctx,
426433
percent: file.percent,
427434
total: info.total,
428-
offset: info.offset
435+
offset: info.offset,
436+
time: (new Date()).getTime()
429437
}));
430438
});
431439

0 commit comments

Comments
 (0)