X Tutup
Skip to content

Commit b464c26

Browse files
committed
use jQuery-File-Upload bitrate on file upload instead of self calculating
1 parent 6cbadba commit b464c26

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

apps/files/js/file-upload.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,12 +1269,11 @@ OC.Uploader.prototype = _.extend({
12691269

12701270
if (this._supportAjaxUploadWithProgress()) {
12711271
//remaining time
1272-
var lastUpdate = new Date().getMilliseconds();
1273-
var lastSize = 0;
12741272
var bufferSize = 20;
12751273
var buffer = [];
12761274
var bufferIndex = 0;
12771275
var bufferTotal = 0;
1276+
var filledBufferSize = 0;
12781277
for(var i = 0; i < bufferSize;i++){
12791278
buffer[i] = 0;
12801279
}
@@ -1308,19 +1307,20 @@ OC.Uploader.prototype = _.extend({
13081307
fileupload.on('fileuploadprogressall', function(e, data) {
13091308
self.log('progress handle fileuploadprogressall', e, data);
13101309
var progress = (data.loaded / data.total) * 100;
1311-
var thisUpdate = new Date().getMilliseconds();
1312-
var diffUpdate = (thisUpdate - lastUpdate)/1000; // eg. 2s
1313-
lastUpdate = thisUpdate;
1314-
var diffSize = data.loaded - lastSize;
1315-
lastSize = data.loaded;
1316-
diffSize = diffSize / diffUpdate; // apply timing factor, eg. 1mb/2s = 0.5mb/s
1317-
var remainingSeconds = ((data.total - data.loaded) / diffSize);
1310+
var remainingBits = (data.total - data.loaded) * 8;
1311+
var remainingSeconds = remainingBits / data.bitrate;
1312+
1313+
//Take the average remaining seconds of the last bufferSize events
1314+
//to prevent fluctuation and provide a smooth experience
13181315
if (isFinite(remainingSeconds) && remainingSeconds >= 0) {
13191316
bufferTotal = bufferTotal - (buffer[bufferIndex]) + remainingSeconds;
1320-
buffer[bufferIndex] = remainingSeconds; //buffer to make it smoother
1317+
buffer[bufferIndex] = remainingSeconds;
13211318
bufferIndex = (bufferIndex + 1) % bufferSize;
1319+
if (filledBufferSize < bufferSize) {
1320+
filledBufferSize++;
1321+
}
13221322
}
1323-
var smoothRemainingSeconds = (bufferTotal / bufferSize); //seconds
1323+
var smoothRemainingSeconds = (bufferTotal / filledBufferSize);
13241324
var h = moment.duration(smoothRemainingSeconds, "seconds").humanize();
13251325
self.$uploadprogressbar.attr('data-loaded', data.loaded);
13261326
self.$uploadprogressbar.attr('data-total', data.total);

changelog/unreleased/37053

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Bugfix: Fix public link upload remaining time estimation
2+
3+
Public link upload wrong remaining time estimation problem has been resolved.
4+
Also, the remaining time calculation logic has been changed for smoother performance.
5+
6+
https://github.com/owncloud/core/pull/37053
7+
https://github.com/owncloud/core/issues/25053

0 commit comments

Comments
 (0)
X Tutup