Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Feature/flexible upload support #1939

Merged
merged 51 commits into from
Mar 9, 2018
Merged
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
80dd701
ports 3000/3001 clash with my local env, and possibly others
Sep 11, 2017
949a958
Start of support for promissory onUploadChunk event
Sep 11, 2017
2b8e681
returned onUploadChunk promise con override method, params, headers, …
Sep 12, 2017
364c2a6
always ensure test server are killed either on test start or stop
Sep 12, 2017
167ad40
don't try to kill test server on CI before tests start
Sep 12, 2017
d861764
forgot to start the test resources server on CI
Sep 12, 2017
6753613
promissory onUpload callback + handle async failure of onUpload/chunk
Sep 13, 2017
ef7b7bc
option to allow upload responses without { "success": true }
Sep 15, 2017
a3d0968
allow default params to be omitted from upload requests
Sep 15, 2017
9a581fd
1st alpha release with most of the changes obviously needed for flexi…
Sep 15, 2017
2e827ce
don't fail upload w/ non-JSON response when requireSuccessJson = false
Sep 15, 2017
f710d04
5.16.0-alpha.1
Sep 15, 2017
494be7c
more flexible chunking.success request support
Sep 15, 2017
2bf5820
5.16.0-alpha.2
Sep 15, 2017
b736f61
Merge branch 'develop' into feature/flexible-upload-support
rnicholus Sep 26, 2017
f9bf070
make sure test servers are never cleaned up before tests run
Oct 9, 2017
7d37ef4
add .editorconfig (can't believe this didn't exist until now)
Oct 9, 2017
11f610b
Allow custom resume keys and data to be specified.
Oct 10, 2017
254065f
include customResumeData in return value of getResumableFilesData API…
Oct 10, 2017
17b5734
add isResumable public API method
Oct 10, 2017
8f57e3c
obey the lint
Oct 10, 2017
f1b8ef2
onUpload rejected Promise does not fail upload
Oct 11, 2017
faf1091
onUpload rejected Promise does not fail upload after all auto-retries…
Oct 11, 2017
5d7afad
introduce chunking.success.resetOnStatus to allow FU to reset a file …
Oct 11, 2017
0b0d668
new API method: isResumable(id)
Oct 12, 2017
e72a779
Allow onUpload resolved Promise to pause the file.
Oct 13, 2017
8eb98d7
Allow per-file chunk sizes to be specified.
Oct 14, 2017
068d891
unit tests for more flexible chunking.success support
Oct 15, 2017
f11bba0
unit tests for new request.requestJsonSuccess and request.omitDefault…
Oct 15, 2017
a4e6575
tests for custom resume data/keys & chunking.success.resetOnStatus
Oct 16, 2017
d74a750
onUpload thenable support tests
Oct 16, 2017
4b39181
Merge branch 'develop' into feature/flexible-upload-support
rnicholus Oct 16, 2017
5b8ab58
onUploadChunk thenable support tests
Oct 16, 2017
53b397d
test for per-file chunk size support
Oct 16, 2017
978d8ad
release 5.16.0-alpha.13
Oct 16, 2017
be3da37
feat(beforeUnload): new option to turn off beforeUnload alert during …
Oct 20, 2017
b8bb659
feat(features.js): auto-detect folder support
Oct 20, 2017
d1b3bef
Allow access to Blob when file status is still SUBMITTING
Oct 27, 2017
77c5c31
docs: options, API, and events doc updates
Oct 31, 2017
9e36d11
TypeScript Definitions Updated
singhjusraj Nov 1, 2017
5bf7145
Merge branch 'develop' into feature/flexible-upload-support
rnicholus Nov 6, 2017
5bf84c1
Merge branch 'develop' into feature/flexible-upload-support
rnicholus Nov 8, 2017
e81d180
Merge branch 'develop' into feature/flexible-upload-support
rnicholus Nov 8, 2017
c7ed6e6
Merge branch 'master' into feature/flexible-upload-support
rnicholus Nov 8, 2017
4f9e765
Merge branch 'master' into feature/flexible-upload-support
Dec 18, 2017
d693100
version case
Dec 18, 2017
923dad3
Merge branch 'master' into feature/flexible-upload-support
rnicholus Jan 27, 2018
db1ce75
Merge branch 'master' into feature/flexible-upload-support
rnicholus Feb 22, 2018
65ffd53
Fix regression that caused more complex resume workflows to fail.
Feb 22, 2018
9eae7ab
added qq.status.UPLOAD_FINALIZING - don't cancel or pause in this state
Feb 22, 2018
a83d4d3
Merge branch 'master' into feature/flexible-upload-support
rnicholus Mar 9, 2018
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
Prev Previous commit
Next Next commit
promissory onUpload callback + handle async failure of onUpload/chunk
rnicholus committed Sep 13, 2017
commit 6753613605e1fb0e9c62aff85ad589a4ff298540
136 changes: 75 additions & 61 deletions client/js/upload-handler/upload.handler.controller.js
Original file line number Diff line number Diff line change
@@ -209,62 +209,68 @@ qq.UploadHandlerController = function(o, namespace) {

var onUploadChunkPromise = options.onUploadChunk(id, name, handler._getChunkDataForCallback(chunkData));

onUploadChunkPromise.then(function(requestOverrides) {
if (!options.isInProgress(id)) {
log(qq.format("Not sending chunked upload request for item {}.{} - no longer in progress.", id, chunkIdx));
}
else {
log(qq.format("Sending chunked upload request for item {}.{}, bytes {}-{} of {}.", id, chunkIdx, chunkData.start + 1, chunkData.end, size));

var uploadChunkData = {
chunkIdx: chunkIdx,
id: id,
overrides: requestOverrides,
resuming: resuming
};

handler.uploadChunk(uploadChunkData).then(
// upload chunk success
function success(response, xhr) {
log("Chunked upload request succeeded for " + id + ", chunk " + chunkIdx);

handler.clearCachedChunk(id, chunkIdx);

var inProgressChunks = handler._getFileState(id).chunking.inProgress || [],
responseToReport = upload.normalizeResponse(response, true),
inProgressChunkIdx = qq.indexOf(inProgressChunks, chunkIdx);

log(qq.format("Chunk {} for file {} uploaded successfully.", chunkIdx, id));

chunked.done(id, chunkIdx, responseToReport, xhr);

if (inProgressChunkIdx >= 0) {
inProgressChunks.splice(inProgressChunkIdx, 1);
}

handler._maybePersistChunkedState(id);

if (!chunked.hasMoreParts(id) && inProgressChunks.length === 0) {
chunked.finalize(id);
}
else if (chunked.hasMoreParts(id)) {
chunked.sendNext(id);
onUploadChunkPromise.then(
function(requestOverrides) {
if (!options.isInProgress(id)) {
log(qq.format("Not sending chunked upload request for item {}.{} - no longer in progress.", id, chunkIdx));
}
else {
log(qq.format("Sending chunked upload request for item {}.{}, bytes {}-{} of {}.", id, chunkIdx, chunkData.start + 1, chunkData.end, size));

var uploadChunkData = {
chunkIdx: chunkIdx,
id: id,
overrides: requestOverrides,
resuming: resuming
};

handler.uploadChunk(uploadChunkData).then(
// upload chunk success
function success(response, xhr) {
log("Chunked upload request succeeded for " + id + ", chunk " + chunkIdx);

handler.clearCachedChunk(id, chunkIdx);

var inProgressChunks = handler._getFileState(id).chunking.inProgress || [],
responseToReport = upload.normalizeResponse(response, true),
inProgressChunkIdx = qq.indexOf(inProgressChunks, chunkIdx);

log(qq.format("Chunk {} for file {} uploaded successfully.", chunkIdx, id));

chunked.done(id, chunkIdx, responseToReport, xhr);

if (inProgressChunkIdx >= 0) {
inProgressChunks.splice(inProgressChunkIdx, 1);
}

handler._maybePersistChunkedState(id);

if (!chunked.hasMoreParts(id) && inProgressChunks.length === 0) {
chunked.finalize(id);
}
else if (chunked.hasMoreParts(id)) {
chunked.sendNext(id);
}
else {
log(qq.format("File ID {} has no more chunks to send and these chunk indexes are still marked as in-progress: {}", id, JSON.stringify(inProgressChunks)));
}
},

// upload chunk failure
function failure(response, xhr) {
chunked.handleFailure(chunkIdx, id, response, xhr);
}
else {
log(qq.format("File ID {} has no more chunks to send and these chunk indexes are still marked as in-progress: {}", id, JSON.stringify(inProgressChunks)));
}
},

// upload chunk failure
function failure(response, xhr) {
chunked.handleFailure(chunkIdx, id, response, xhr);
}
)
.done(function () {
handler.clearXhr(id, chunkIdx);
});
)
.done(function () {
handler.clearXhr(id, chunkIdx);
});
}
},

function(error) {
chunked.handleFailure(chunkIdx, id, error, null);
}
});
);
}
}
},
@@ -573,14 +579,22 @@ qq.UploadHandlerController = function(o, namespace) {
throw new qq.Error(id + " is not a valid file ID to upload!");
}

options.onUpload(id, name);
var onUploadPromise = options.onUpload(id, name);

if (chunkingPossible && handler._shouldChunkThisFile(id)) {
chunked.sendNext(id);
}
else {
simple.send(id, name);
}
onUploadPromise.then(
function() {
if (chunkingPossible && handler._shouldChunkThisFile(id)) {
chunked.sendNext(id);
}
else {
simple.send(id, name);
}
},

function(error) {
throw new qq.Error(id + " upload start aborted due to rejected onUpload Promise - details: " + error);
}
);
},

start: function(id) {
10 changes: 9 additions & 1 deletion client/js/uploader.basic.api.js
Original file line number Diff line number Diff line change
@@ -771,7 +771,14 @@
onUploadPrep: qq.bind(this._onUploadPrep, this),
onUpload: function(id, name) {
self._onUpload(id, name);
self._options.callbacks.onUpload(id, name);
var onUploadResult = self._options.callbacks.onUpload(id, name);

if (qq.isGenericPromise(onUploadResult)) {
self.log(qq.format("onUpload for {} returned a Promise - waiting for resolution.", id));
return onUploadResult;
}

return new qq.Promise().success();
},
onUploadChunk: function(id, name, chunkData) {
self._onUploadChunk(id, chunkData);
@@ -781,6 +788,7 @@
self.log(qq.format("onUploadChunk for {}.{} returned a Promise - waiting for resolution.", id, chunkData.partIndex));
return onUploadChunkResult;
}

return new qq.Promise().success();
},
onUploadChunkSuccess: function(id, chunkData, result, xhr) {