aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
authorBekcpear <ink2.0plus@gmail.com>2017-05-30 20:58:24 +0800
committerBekcpear <ink2.0plus@gmail.com>2017-06-16 15:33:10 +0800
commit82e263ed043b38b76b54e8eb41c0fe282798017d (patch)
tree5b4a8356c4f64d53e05a15866b0c7b11cdf9477b /apps/files/js
parent1d227d83c02783ab9e8ed7d63e51771719e25ae3 (diff)
downloadnextcloud-server-82e263ed043b38b76b54e8eb41c0fe282798017d.tar.gz
nextcloud-server-82e263ed043b38b76b54e8eb41c0fe282798017d.zip
Fix upload remaining time
The upload remaining time is always 'a few second' whatever a big or a small file uploading. This commit fixes it. The `new Date().getMilliseconds()` only return a three digits number. When time arrived the next second, the millisecond start from ZERO again. So `new Date().getTime()` is the righe choice. And remaining time variables shoule be initialized when the file starts uploading, otherwise the remaining time of a new upload will always be 'Infinity years' until you refresh the page. Signed-off-by: Yaojin Qian <i@ume.ink>
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/file-upload.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 1c5758ca50b..87b6a76d0ec 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -956,16 +956,7 @@ OC.Uploader.prototype = _.extend({
if (this._supportAjaxUploadWithProgress()) {
//remaining time
- var lastUpdate = new Date().getMilliseconds();
- var lastSize = 0;
- var bufferSize = 20;
- var buffer = [];
- var bufferIndex = 0;
- var bufferIndex2 = 0;
- var bufferTotal = 0;
- for(var i = 0; i < bufferSize;i++){
- buffer[i] = 0;
- }
+ var lastUpdate, lastSize, bufferSize, buffer, bufferIndex, bufferIndex2, bufferTotal;
// add progress handlers
fileupload.on('fileuploadadd', function(e, data) {
@@ -986,6 +977,17 @@ OC.Uploader.prototype = _.extend({
+ '</span></em>');
$('#uploadprogressbar').tooltip({placement: 'bottom'});
self._showProgressBar();
+ // initial remaining time variables
+ lastUpdate = new Date().getTime();
+ lastSize = 0;
+ bufferSize = 20;
+ buffer = [];
+ bufferIndex = 0;
+ bufferIndex2 = 0;
+ bufferTotal = 0;
+ for(var i = 0; i < bufferSize; i++){
+ buffer[i] = 0;
+ }
self.trigger('start', e, data);
});
fileupload.on('fileuploadprogress', function(e, data) {
@@ -996,12 +998,12 @@ OC.Uploader.prototype = _.extend({
fileupload.on('fileuploadprogressall', function(e, data) {
self.log('progress handle fileuploadprogressall', e, data);
var progress = (data.loaded / data.total) * 100;
- var thisUpdate = new Date().getMilliseconds();
+ var thisUpdate = new Date().getTime();
var diffUpdate = (thisUpdate - lastUpdate)/1000; // eg. 2s
lastUpdate = thisUpdate;
var diffSize = data.loaded - lastSize;
lastSize = data.loaded;
- diffSize = diffSize / diffUpdate; // apply timing factor, eg. 1mb/2s = 0.5mb/s
+ diffSize = diffSize / diffUpdate; // apply timing factor, eg. 1MiB/2s = 0.5MiB/s, unit is byte per second
var remainingSeconds = ((data.total - data.loaded) / diffSize);
if(remainingSeconds >= 0) {
bufferTotal = bufferTotal - (buffer[bufferIndex]) + remainingSeconds;