Skip to content

Commit a3318db

Browse files
author
zhangheng
committed
fix progress bug
1 parent 24f816e commit a3318db

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

src/statisticsLog.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ export class StatisticsLogger{
1111
send(logString, token){
1212
let xhr = createXHR();
1313
let count = 0;
14+
let self = this;
1415
xhr.open("POST", "https://uplog.qbox.me/log/3");
1516
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
1617
xhr.setRequestHeader("Authorization", "UpToken " + token);
1718
xhr.onreadystatechange = function () {
1819
if (xhr.readyState === 4) {
1920
if (xhr.status !== 200) {
2021
count++;
21-
count <= 3 ? xhr.send(logString) : "";
22-
}
22+
count <= 3 ? self.send(logString) : "";
23+
}
2324
}
2425
};
2526
xhr.send(logString);
2627
}
2728

28-
}
29+
}

src/upload.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
request,
1515
computeMd5,
1616
getUploadUrl,
17-
isAndroidBrowser,
1817
filterParams
1918
} from "./utils";
2019

@@ -57,7 +56,6 @@ export class UploadManager {
5756
this.onError = () => {};
5857
this.onComplete = () => {};
5958
this.retryCount = 0;
60-
this.isAndroidBrowser = isAndroidBrowser();
6159
Object.assign(this, handlers);
6260
}
6361

@@ -190,7 +188,7 @@ export class UploadManager {
190188
removeLocalFileInfo(this.file);
191189
return;
192190
}
193-
setLocalFileInfo(this.file, this.ctxList);
191+
setLocalFileInfo(this.file, this.ctxList);
194192
}
195193
);
196194
return result;
@@ -233,17 +231,13 @@ export class UploadManager {
233231
onProgress,
234232
onCreate
235233
}).then(response => {
236-
if (this.isAndroidBrowser) {
237-
// 对于低版本安卓浏览器,因为无法触发 xhr 的 progress 事件,这里 fake 下
238-
onProgress({ loaded: chunk.size });
239-
}
234+
onProgress({ loaded: chunk.size });
240235
this.ctxList[index] = {
241236
time: new Date().getTime(),
242237
ctx: response.data.ctx,
243238
size: chunk.size,
244239
md5: md5
245240
};
246-
console.log(this.ctxList);
247241
});
248242
});
249243
}
@@ -281,7 +275,7 @@ export class UploadManager {
281275

282276
finishDirectProgress(){
283277
// 对于低版本安卓浏览器,progress 为 null, 这里 fake 下
284-
if (this.isAndroidBrowser) {
278+
if (!this.progress) {
285279
this.progress = { total: this.getProgressInfoItem(this.file.size, this.file.size) };
286280
this.onData(this.progress);
287281
return;

src/utils.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,3 @@ export function getTransform(image, orientation) {
332332
};
333333
}
334334
}
335-
336-
// 检查低版本浏览器的措施
337-
export function isAndroidBrowser() {
338-
let navU = navigator.userAgent;
339-
// Android Mobile
340-
let isAndroidMobile = navU.indexOf("Android") > -1
341-
&& navU.indexOf("Mozilla/5.0") > -1 && navU.indexOf("AppleWebKit") > -1;
342-
// Android Browser (not Chrome)
343-
let regExAppleWebKit = new RegExp(/AppleWebKit\/([\d.]+)/);
344-
let resultAppleWebKitRegEx = regExAppleWebKit.exec(navU);
345-
let appleWebKitVersion = (resultAppleWebKitRegEx === null ? null : parseFloat(regExAppleWebKit.exec(navU)[1]));
346-
let isAndroidBrowser = isAndroidMobile && appleWebKitVersion !== null && appleWebKitVersion < 537;
347-
return isAndroidBrowser;
348-
}

0 commit comments

Comments
 (0)