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

Commit

Permalink
feat(uploader.basic.js): more flexible server endpoint support (#1939)
Browse files Browse the repository at this point in the history
* Local dev/testing ports 3000/3001 clash with my local env, and possibly others - moving to 4000/4001.

* returned onUploadChunk promise can override method, params, headers, & url
* promissory onUpload callback

* always ensure test server are killed either on test start or stop

* don't try to kill test server on CI before tests start

* option to allow upload responses without { "success": true }

* allow default params to be omitted from upload requests

* don't fail upload w/ non-JSON response when requireSuccessJson = false

* more flexible chunking.success request support

* add .editorconfig (can't believe this didn't exist until now)

* Allow custom resume keys and data to be specified.

* include customResumeData in return value of getResumableFilesData API method

* add isResumable public API method

* introduce chunking.success.resetOnStatus to allow FU to reset a file based on chunking.success response code

* new API method: isResumable(id)

* Allow onUpload resolved Promise to pause the file.
Use case: When onUpload is called, you make a request to your server to see if the file already exists. If it does, you want to let your user decide if they want to overwrite the file, or cancel the upload entirely. While waiting for user input you don't want to hold a spot in the upload queue. If the user decided to overwrite the file, call the `continueUpload` API method.

* Allow per-file chunk sizes to be specified.
chunking.partSize now accepts a function, which passes the file ID and size

* feat(beforeUnload): new option to turn off beforeUnload alert during uploads

* feat(features.js): auto-detect folder support

* Allow access to Blob when file status is still SUBMITTING

* docs: options, API, and events doc updates

* added qq.status.UPLOAD_FINALIZING - don't cancel or pause in this state

closes #848
closes #1697
closes #1755
closes #1325
closes #1647
closes #1703
  • Loading branch information
rnicholus committed Mar 9, 2018
1 parent 007c4de commit 5be9ba1
Show file tree
Hide file tree
Showing 31 changed files with 1,354 additions and 201 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[{*.js}]
charset = utf-8
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.*
!.editorconfig
*.ipr
*~
.*.sw[a-z]
Expand Down
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -322,21 +322,27 @@ start-test-resources-server: test-resources-server.PID
start-root-server: root-server.PID

test-resources-server.PID:
$(npm-bin)/static test/unit/resources -H '{"Access-Control-Allow-Origin": "*"}' -p 3000 & echo $$! > $@
$(npm-bin)/static test/unit/resources -H '{"Access-Control-Allow-Origin": "*"}' -p 4000 & echo $$! > $@

root-server.PID:
$(npm-bin)/static . -p 3001 & echo $$! > $@
$(npm-bin)/static . -p 4001 & echo $$! > $@

stop-test-resources-server: test-resources-server.PID
kill `cat $<` && rm $<

stop-root-server: root-server.PID
kill `cat $<` && rm $<

test: start-test-resources-server start-root-server build-all-ui
test:
$(MAKE) stop-test-resources-server
$(MAKE) stop-root-server
$(MAKE) start-test-resources-server
$(MAKE) start-root-server
$(MAKE) build-all-ui
$(npm-bin)/karma start config/karma.conf.js
make stop-test-resources-server
make stop-root-server
$(MAKE) stop-test-resources-server
$(MAKE) stop-root-server
.PHONY: test

zip: zip-traditional zip-s3 zip-azure zip-all

Expand Down
5 changes: 4 additions & 1 deletion client/js/azure/azure.xhr.upload.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ qq.azure.XhrUploadHandler = function(spec, proxy) {
}

qq.extend(this, {
uploadChunk: function(id, chunkIdx) {
uploadChunk: function(params) {
var chunkIdx = params.chunkIdx;
var id = params.id;

var promise = new qq.Promise();

getSignedUrl(id, chunkIdx).then(
Expand Down
14 changes: 7 additions & 7 deletions client/js/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ qq.supportedFeatures = (function() {
return supported;
}

//only way to test for Filesystem API support since webkit does not expose the DataTransfer interface
function isChrome21OrHigher() {
return (qq.chrome() || qq.opera()) &&
navigator.userAgent.match(/Chrome\/[2][1-9]|Chrome\/[3-9][0-9]/) !== undefined;
}

//only way to test for complete Clipboard API support at this time
function isChrome14OrHigher() {
return (qq.chrome() || qq.opera()) &&
Expand Down Expand Up @@ -109,7 +103,13 @@ qq.supportedFeatures = (function() {

supportsFileDrop = supportsAjaxFileUploading && isDragAndDropSupported();

supportsFolderDrop = supportsFileDrop && isChrome21OrHigher();
// adapted from https://stackoverflow.com/a/23278460/486979
supportsFolderDrop = supportsFileDrop && (function() {
var input = document.createElement("input");

input.type = "file";
return !!("webkitdirectory" in (input || document.querySelectorAll("input[type=file]")[0]));
}());

supportsChunking = supportsAjaxFileUploading && qq.isFileChunkingSupported();

Expand Down
9 changes: 7 additions & 2 deletions client/js/s3/s3.xhr.upload.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ qq.s3.XhrUploadHandler = function(spec, proxy) {
}
},

start: function(id, optChunkIdx) {
start: function(params) {
var id = params.id;
var optChunkIdx = params.chunkIdx;

var promise = new qq.Promise();

upload.key.promise(id).then(function() {
Expand Down Expand Up @@ -587,7 +590,9 @@ qq.s3.XhrUploadHandler = function(spec, proxy) {

qq.extend(this, {
uploadChunk: upload.start,
uploadFile: upload.start
uploadFile: function(id) {
return upload.start({ id: id });
}
});

qq.extend(this, new qq.XhrUploadHandler({
Expand Down
17 changes: 11 additions & 6 deletions client/js/traditional/all-chunks-done.ajax.requester.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ qq.traditional.AllChunksDoneAjaxRequester = function(o) {
"use strict";

var requester,
method = "POST",
options = {
cors: {
allowXdr: false,
expected: false,
sendCredentials: false
},
endpoint: null,
log: function(str, level) {}
log: function(str, level) {},
method: "POST"
},
promises = {},
endpointHandler = {
get: function(id) {
if (qq.isFunction(options.endpoint)) {
return options.endpoint(id);
}

return options.endpoint;
}
};
Expand All @@ -31,8 +35,9 @@ qq.traditional.AllChunksDoneAjaxRequester = function(o) {

requester = qq.extend(this, new qq.AjaxRequester({
acceptHeader: "application/json",
validMethods: [method],
method: method,
contentType: options.jsonPayload ? "application/json" : "application/x-www-form-urlencoded",
validMethods: [options.method],
method: options.method,
endpointStore: endpointHandler,
allowXRequestedWithAndCacheControl: false,
cors: options.cors,
Expand Down Expand Up @@ -60,8 +65,8 @@ qq.traditional.AllChunksDoneAjaxRequester = function(o) {
promises[id] = promise;

requester.initTransport(id)
.withParams(params)
.withHeaders(headers)
.withParams(options.params(id) || params)
.withHeaders(options.headers(id) || headers)
.send(xhr);

return promise;
Expand Down

0 comments on commit 5be9ba1

Please sign in to comment.