Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,32 @@ OC.FileUpload.prototype = {
);
},

_delete: function() {
if (this.data.isChunked) {
this._deleteChunkFolder()
}
this.deleteUpload();
},

/**
* Abort the upload
*/
abort: function() {
if (this.data.isChunked) {
this._deleteChunkFolder();
if (this.aborted) {
return
}
this.data.abort();
this.deleteUpload();
this.aborted = true;
this._delete();
},

/**
* Fail the upload
*/
fail: function() {
this.deleteUpload();
if (this.data.isChunked) {
this._deleteChunkFolder();
if (this.aborted) {
return
}
this._delete();
},

/**
Expand Down Expand Up @@ -679,7 +685,26 @@ OC.Uploader.prototype = _.extend({
return;
}

delete this._uploads[upload.data.uploadId];
// defer as some calls/chunks might still be busy failing, so we need
// the upload info there still
var self = this;
var uploadId = upload.data.uploadId;
// mark as deleted for the progress bar
this._uploads[uploadId].deleted = true;
window.setTimeout(function() {
delete self._uploads[uploadId];
}, 5000)
},

_activeUploadCount: function() {
var count = 0;
for (var key in this._uploads) {
if (!this._uploads[key].deleted) {
count++;
}
}

return count;
},

showUploadCancelMessage: _.debounce(function() {
Expand Down Expand Up @@ -905,6 +930,7 @@ OC.Uploader.prototype = _.extend({
if ($uploadEl.exists()) {
this.progressBar.on('cancel', function() {
self.cancelUploads();
self.showUploadCancelMessage();
});

this.fileUploadParam = {
Expand Down Expand Up @@ -1075,14 +1101,18 @@ OC.Uploader.prototype = _.extend({
var upload = self.getUpload(data);
var status = null;
if (upload) {
if (upload.aborted) {
// uploads might fail with errors from the server when aborted
return
}
status = upload.getResponseStatus();
}
self.log('fail', e, upload);

self.removeUpload(upload);

if (data.textStatus === 'abort' || data.errorThrown === 'abort') {
self.showUploadCancelMessage();
return
} else if (status === 412) {
// file already exists
self.showConflict(upload);
Expand Down Expand Up @@ -1283,6 +1313,10 @@ OC.Uploader.prototype = _.extend({
fileupload.on('fileuploadchunksend', function(e, data) {
// modify the request to adjust it to our own chunking
var upload = self.getUpload(data);
if (!upload) {
// likely cancelled
return
}
var range = data.contentRange.split(' ')[1];
var chunkId = range.split('/')[0].split('-')[0];
data.url = OC.getRootPath() +
Expand All @@ -1298,9 +1332,9 @@ OC.Uploader.prototype = _.extend({

self._pendingUploadDoneCount++;

upload.done().then(function() {
upload.done().always(function() {
self._pendingUploadDoneCount--;
if (Object.keys(self._uploads).length === 0 && self._pendingUploadDoneCount === 0) {
if (self._activeUploadCount() === 0 && self._pendingUploadDoneCount === 0) {
// All the uploads ended and there is no pending
// operation, so hide the progress bar.
// Note that this happens here only with chunked
Expand All @@ -1314,9 +1348,13 @@ OC.Uploader.prototype = _.extend({
// hides the progress bar in that case).
self._hideProgressBar();
}

}).done(function() {
self.trigger('done', e, upload);
}).fail(function(status, response) {
if (upload.aborted) {
return
}

var message = response.message;
if (status === 507) {
// not enough space
Expand Down