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

Use native Promise #1986

Open
wants to merge 73 commits into
base: release/6.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
605d6a8
refactor: require native Promise implementation
bradleyayers Mar 23, 2018
80eb375
refactor: qq.s3.util.generateAwsParams to return Promise
bradleyayers Mar 25, 2018
b96500a
refactor: lint indentation
bradleyayers Mar 25, 2018
15458df
refactor: qq.azure.FineUploaderBasic._determineBlobName use Promise
bradleyayers Mar 25, 2018
8093491
refactor: qq.Exif.seekToApp1 use Promise
bradleyayers Mar 25, 2018
a29e398
refactor: qq.readBlobToHex use Promise
bradleyayers Mar 25, 2018
0099002
refactor: qq.Exif.getApp1Offset to use Promise
bradleyayers Mar 25, 2018
45f7816
refactor: qq.Exif.isLittleEndian to use Promise
bradleyayers Mar 25, 2018
7bde261
refactor: qq.Exif.getDirEntryCount to use Promise
bradleyayers Mar 25, 2018
3a6f27e
refactor: qq.Exif.parse to use Promise
bradleyayers Mar 25, 2018
674071a
refactor: qq.Scalar.scaleImage to use Promise
bradleyayers Mar 25, 2018
d4fae19
refactor: qq.Scalar._generateScaledImage to use Promise
bradleyayers Mar 25, 2018
5d7c393
refactor: qq.Scalar._insertExifHeader to use Promise
bradleyayers Mar 25, 2018
e7ef8b3
refactor: renderImageToDataURL to use Promise
bradleyayers Mar 25, 2018
5a2b392
refactor: renderImageToCanvasWithCustomResizer to use Promise
bradleyayers Mar 25, 2018
ed1dbe7
refactor: uploadChunk and uploadFile to use Promise
bradleyayers Mar 26, 2018
4e22540
refactor: UploadHandler#finalizeChunks to use Promise
bradleyayers Mar 26, 2018
07f0033
refactor: determineBlobUrl to use Promise
bradleyayers Mar 26, 2018
9afcdbb
refactor: lint
bradleyayers Mar 26, 2018
fc81e29
refactor: qq.Identify.isPreviewable to use Promise
bradleyayers Mar 26, 2018
b1954f4
refactor: renderImageToCanvas to use Promise
bradleyayers Mar 26, 2018
4a2367d
refactor: traverseFileTree to use Promise
bradleyayers Mar 26, 2018
75feb04
refactor: handleDataTransfer to use Promise
bradleyayers Mar 26, 2018
bf2e80b
refactor: getFilesInDirectory to use Promise
bradleyayers Mar 26, 2018
3a7c564
refactor: _onComplete to use Promise
bradleyayers Mar 26, 2018
bce7cf9
refactor: getWidthHeight to use Promise
bradleyayers Mar 26, 2018
3417d6e
refactor: qq.ImageValidation.validate to use Promise
bradleyayers Mar 26, 2018
59e134e
refactor: qq.ImageGenerator dummyExif to use Promise
bradleyayers Mar 26, 2018
5e10cbb
refactor: registerThumbnailRenderedListener to use Promise
bradleyayers Mar 26, 2018
027ae21
refactor: lint
bradleyayers Mar 26, 2018
765f9c3
refactor: drawFromUrl to use Promise
bradleyayers Mar 26, 2018
1836412
refactor: qq.ImageGenerator.generate to use Promise
bradleyayers Mar 26, 2018
acaf7f3
refactor: qq.s3.AbortMultipartAjaxRequester getHeaders to use Promise
bradleyayers Mar 26, 2018
3d3bc7c
refactor: qq.s3.RequestSigner getEncodedHashedPayload to use Promise
bradleyayers Mar 26, 2018
befcefe
refactor: qq.s3.RequestSigner getStringToSignArtifacts to use Promise
bradleyayers Mar 26, 2018
01e9b59
refactor: qq.s3.RequestSigner getToSign to use Promise
bradleyayers Mar 26, 2018
91133ce
refactor: qq.s3.FormUploadHandler createForm to use Promise
bradleyayers Mar 26, 2018
b6119eb
refactor: qq.s3.FormUploadHandler handleUpload to use Promise
bradleyayers Mar 26, 2018
bd764f2
refactor: qq.s3.XhrUploadHandler initHeaders to use Promise
bradleyayers Mar 26, 2018
8d2b6fb
refactor: qq.s3.XhrUploadHandler put to use Promise
bradleyayers Mar 26, 2018
5290511
refactor: qq.s3.XhrUploadHandler setup to use Promise
bradleyayers Mar 26, 2018
f8aeaa5
refactor: qq.s3.XhrUploadHandler bucket.promise to use Promise
bradleyayers Mar 26, 2018
1df0ccf
refactor: qq.s3.XhrUploadHandler.setup to use Promise
bradleyayers Mar 26, 2018
52bd7dd
refactor: Uploader getKey to return Promise
bradleyayers Mar 26, 2018
3c3ee2f
refactor: upload() to return Promise
bradleyayers Mar 27, 2018
8e347bb
refactor: handleFileItems() to return Promise
bradleyayers Mar 27, 2018
fb61367
refactor: qq.Session.refresh to return Promise
bradleyayers Mar 27, 2018
c6b7f96
refactor: qq.s3.*AjaxRequester.getHeaders to return Promise
bradleyayers Mar 27, 2018
7676f26
refactor: qq.s3.InitiateMultipartAjaxRequester.send to return Promise
bradleyayers Mar 27, 2018
9d3cb9d
refactor: qq.s3.CompleteMultipartAjaxRequester.send to return Promise
bradleyayers Mar 27, 2018
5b9546c
refactor: onExpired to return Promise
bradleyayers Mar 27, 2018
58b19d7
refactor: _determineObjectPropertyValue to return Promise
bradleyayers Mar 27, 2018
9bae71c
refactor: qq.s3.FineUploaderBasic._determineKeyName to return Promise
bradleyayers Mar 27, 2018
a6a432b
refactor: qq.azure.PutBlock.upload to return Promise
bradleyayers Mar 27, 2018
e317ed0
refactor: qq.azure.PutBlob.upload to return Promise
bradleyayers Mar 27, 2018
51a4b57
refactor: qq.azure.PutBlockList.send to return Promise
bradleyayers Mar 27, 2018
1639265
refactor: qq.traditional.AllChunksDoneAjaxRequester.complete to retur…
bradleyayers Mar 27, 2018
53f90d0
refactor: qq.traditional.FormUploadHandler.uploadFile to return Promise
bradleyayers Mar 27, 2018
3e653bc
refactor: qq.Templating.showDialog to return Promise
bradleyayers Mar 27, 2018
cab1b63
refactor: drawThumbnail to return Promise
bradleyayers Mar 27, 2018
c1fa3f3
refactor: onComplete to use instanceof Promise
bradleyayers Mar 27, 2018
fd6cb33
refactor: onCancel to return Promise
bradleyayers Mar 27, 2018
4c8d4b3
refactor: onUploadChunk to return Promise
bradleyayers Mar 27, 2018
bad4382
refactor: generateHeaders to return Promise
bradleyayers Mar 27, 2018
3c7b3ed
refactor: qq.Templating to use Promise
bradleyayers Mar 27, 2018
5d6bf6d
refactor: qq.UploadSuccessAjaxRequester.sendSuccessRequest to use Pro…
bradleyayers Mar 27, 2018
d74ba0b
refactor: _validateFileOrBlobData to use Promise
bradleyayers Mar 27, 2018
23f5ed4
refactor: qq.UploadHandler.cancel to use Promise
bradleyayers Mar 27, 2018
5d63d39
refactor: docs to use Promise
bradleyayers Mar 27, 2018
fd2ad47
refactor: tests to use native Promise, remove Q.js and qq.Promise
bradleyayers Mar 27, 2018
437ec5b
refactor: remove isGenericPromise, use instanceof Promise
bradleyayers Mar 27, 2018
7e4473a
refactor: remove CSS references to qq.Promise
bradleyayers Mar 27, 2018
2f9f381
fix: Remove PromiseOptions from TypeScript definitions
bradleyayers Apr 1, 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
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
"couch" : false, // Enable globals exposed by CouchDB.
"devel" : false, // Allow development statements e.g. `console.log();`.
"dojo" : false, // Enable globals exposed by Dojo Toolkit.
"globals" : {
"Promise": true
},
"jquery" : true, // Enable globals exposed by jQuery JavaScript library.
"mootools" : false, // Enable globals exposed by MooTools JavaScript framework.
"node" : false, // Enable globals available when code is running inside of the NodeJS runtime environment.
Expand Down
214 changes: 106 additions & 108 deletions client/js/azure/azure.xhr.upload.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,73 +59,63 @@ qq.azure.XhrUploadHandler = function(spec, proxy) {
};

function combineChunks(id) {
var promise = new qq.Promise();

getSignedUrl(id).then(function(sasUri) {
var mimeType = handler._getMimeType(id),
blockIdEntries = handler._getPersistableData(id).blockIdEntries;

api.putBlockList.send(id, sasUri, blockIdEntries, mimeType, function(xhr) {
handler._registerXhr(id, null, xhr, api.putBlockList);
})
.then(function(xhr) {
log("Success combining chunks for id " + id);
promise.success({}, xhr);
}, function(xhr) {
log("Attempt to combine chunks failed for id " + id, "error");
handleFailure(xhr, promise);
});

},
promise.failure);

return promise;
return new Promise(function(resolve, reject) {
getSignedUrl(id).then(function(sasUri) {
var mimeType = handler._getMimeType(id),
blockIdEntries = handler._getPersistableData(id).blockIdEntries;

api.putBlockList.send(id, sasUri, blockIdEntries, mimeType, function(xhr) {
handler._registerXhr(id, null, xhr, api.putBlockList);
})
.then(function(xhr) {
log("Success combining chunks for id " + id);
resolve({response: {}, xhr: xhr});
}, function(xhr) {
log("Attempt to combine chunks failed for id " + id, "error");
reject(buildError(xhr));
});
},
reject);
});
}

function determineBlobUrl(id) {
var containerUrl = endpointStore.get(id),
promise = new qq.Promise(),
getBlobNameSuccess = function(blobName) {
handler._setThirdPartyFileId(id, blobName);
promise.success(containerUrl + "/" + blobName);
},
getBlobNameFailure = function(reason) {
promise.failure(reason);
};

onGetBlobName(id).then(getBlobNameSuccess, getBlobNameFailure);
var containerUrl = endpointStore.get(id);

return promise;
return new Promise(function(resolve, reject) {
onGetBlobName(id).then(function(blobName) {
handler._setThirdPartyFileId(id, blobName);
resolve(containerUrl + "/" + blobName);
}, reject);
});
}

function getSignedUrl(id, optChunkIdx) {
// We may have multiple SAS requests in progress for the same file, so we must include the chunk idx
// as part of the ID when communicating with the SAS ajax requester to avoid collisions.
var getSasId = optChunkIdx == null ? id : id + "." + optChunkIdx,

promise = new qq.Promise(),
getSasSuccess = function(sasUri) {
log("GET SAS request succeeded.");
promise.success(sasUri);
},
getSasFailure = function(reason, getSasXhr) {
log("GET SAS request failed: " + reason, "error");
promise.failure({error: "Problem communicating with local server"}, getSasXhr);
},
determineBlobUrlSuccess = function(blobUrl) {
api.getSasForPutBlobOrBlock.request(getSasId, blobUrl).then(
getSasSuccess,
getSasFailure
);
},
determineBlobUrlFailure = function(reason) {
log(qq.format("Failed to determine blob name for ID {} - {}", id, reason), "error");
promise.failure({error: reason});
};

determineBlobUrl(id).then(determineBlobUrlSuccess, determineBlobUrlFailure);
return new Promise(function(resolve, reject) {
// We may have multiple SAS requests in progress for the same file, so we must include the chunk idx
// as part of the ID when communicating with the SAS ajax requester to avoid collisions.
var getSasId = optChunkIdx == null ? id : id + "." + optChunkIdx,
getSasSuccess = function(sasUri) {
log("GET SAS request succeeded.");
resolve(sasUri);
},
getSasFailure = function(error) {
log("GET SAS request failed: " + error.message, "error");
reject(error);
},
determineBlobUrlSuccess = function(blobUrl) {
api.getSasForPutBlobOrBlock.request(getSasId, blobUrl).then(
getSasSuccess,
getSasFailure
);
},
determineBlobUrlFailure = function(error) {
log(qq.format("Failed to determine blob name for ID {} - {}", id, error.message), "error");
reject(error);
};

return promise;
determineBlobUrl(id).then(determineBlobUrlSuccess, determineBlobUrlFailure);
});
}

function handleFailure(xhr, promise) {
Expand All @@ -138,68 +128,76 @@ qq.azure.XhrUploadHandler = function(spec, proxy) {
});
}

function buildError(xhr) {
var azureError = qq.azure.util.parseAzureError(xhr.responseText, log),
errorMsg = "Problem sending file to Azure",
error = new Error(errorMsg);

error.error = errorMsg;
error.azureError = azureError && azureError.message;
error.reset = xhr.status === 403;

return error;
}

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

var promise = new qq.Promise();
return new Promise(function(resolve, reject) {
getSignedUrl(id, chunkIdx).then(
function(sasUri) {
var xhr = handler._createXhr(id, chunkIdx),
chunkData = handler._getChunkData(id, chunkIdx);

handler._registerProgressHandler(id, chunkIdx, chunkData.size);
handler._registerXhr(id, chunkIdx, xhr, api.putBlock);

// We may have multiple put block requests in progress for the same file, so we must include the chunk idx
// as part of the ID when communicating with the put block ajax requester to avoid collisions.
api.putBlock.upload(id + "." + chunkIdx, xhr, sasUri, chunkIdx, chunkData.blob).then(
function(blockIdEntry) {
if (!handler._getPersistableData(id).blockIdEntries) {
handler._getPersistableData(id).blockIdEntries = [];
}

handler._getPersistableData(id).blockIdEntries.push(blockIdEntry);
log("Put Block call succeeded for " + id);
resolve({response: {}, xhr: xhr});
},
function() {
log(qq.format("Put Block call failed for ID {} on part {}", id, chunkIdx), "error");
reject(buildError(xhr));
}
);
},
reject
);
});
},

getSignedUrl(id, chunkIdx).then(
function(sasUri) {
var xhr = handler._createXhr(id, chunkIdx),
chunkData = handler._getChunkData(id, chunkIdx);
uploadFile: function(id) {
var fileOrBlob = handler.getFile(id);

handler._registerProgressHandler(id, chunkIdx, chunkData.size);
handler._registerXhr(id, chunkIdx, xhr, api.putBlock);
return new Promise(function(resolve, reject) {
getSignedUrl(id).then(function(sasUri) {
var xhr = handler._createXhr(id);

// We may have multiple put block requests in progress for the same file, so we must include the chunk idx
// as part of the ID when communicating with the put block ajax requester to avoid collisions.
api.putBlock.upload(id + "." + chunkIdx, xhr, sasUri, chunkIdx, chunkData.blob).then(
function(blockIdEntry) {
if (!handler._getPersistableData(id).blockIdEntries) {
handler._getPersistableData(id).blockIdEntries = [];
}
handler._registerProgressHandler(id);

handler._getPersistableData(id).blockIdEntries.push(blockIdEntry);
log("Put Block call succeeded for " + id);
promise.success({}, xhr);
api.putBlob.upload(id, xhr, sasUri, fileOrBlob).then(
function() {
log("Put Blob call succeeded for " + id);
resolve({response: {}, xhr: xhr});
},
function() {
log(qq.format("Put Block call failed for ID {} on part {}", id, chunkIdx), "error");
handleFailure(xhr, promise);
log("Put Blob call failed for " + id, "error");
reject(buildError(xhr));
}
);
},
promise.failure
);

return promise;
},

uploadFile: function(id) {
var promise = new qq.Promise(),
fileOrBlob = handler.getFile(id);

getSignedUrl(id).then(function(sasUri) {
var xhr = handler._createXhr(id);

handler._registerProgressHandler(id);

api.putBlob.upload(id, xhr, sasUri, fileOrBlob).then(
function() {
log("Put Blob call succeeded for " + id);
promise.success({}, xhr);
},
function() {
log("Put Blob call failed for " + id, "error");
handleFailure(xhr, promise);
}
);
},
promise.failure);

return promise;
}, reject);
});
}
});

Expand Down
38 changes: 21 additions & 17 deletions client/js/azure/get-sas.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ qq.azure.GetSas = function(o) {
qq.extend(options, o);

function sasResponseReceived(id, xhr, isError) {
var promise = requestPromises[id];
var promise = requestPromises[id],
error;

if (isError) {
promise.failure("Received response code " + xhr.status, xhr);
error = new Error("Received response code " + xhr.status);
error.xhr = xhr;
promise.reject(error);
}
else {
if (xhr.responseText.length) {
promise.success(xhr.responseText);
promise.resolve(xhr.responseText);
}
else {
promise.failure("Empty response.", xhr);
error = new Error("Empty response.");
error.xhr = xhr;
promise.reject(error);
}
}

Expand All @@ -56,22 +61,21 @@ qq.azure.GetSas = function(o) {

qq.extend(this, {
request: function(id, blobUri) {
var requestPromise = new qq.Promise(),
restVerb = options.restRequestVerb;
return new Promise(function(resolve, reject) {
var restVerb = options.restRequestVerb;

options.log(qq.format("Submitting GET SAS request for a {} REST request related to file ID {}.", restVerb, id));
options.log(qq.format("Submitting GET SAS request for a {} REST request related to file ID {}.", restVerb, id));

requestPromises[id] = requestPromise;
requestPromises[id] = {resolve: resolve, reject: reject};

requester.initTransport(id)
.withParams({
bloburi: blobUri,
_method: restVerb
})
.withCacheBuster()
.send();

return requestPromise;
requester.initTransport(id)
.withParams({
bloburi: blobUri,
_method: restVerb
})
.withCacheBuster()
.send();
});
}
});
};
24 changes: 11 additions & 13 deletions client/js/azure/rest/put-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,28 @@ qq.azure.PutBlob = function(o) {
delete promises[id];

if (isError) {
promise.failure();
promise.reject();
}
else {
promise.success();
promise.resolve();
}
}
}));

qq.extend(this, {
method: method,
upload: function(id, xhr, url, file) {
var promise = new qq.Promise();
return new Promise(function(resolve, reject) {
options.log("Submitting Put Blob request for " + id);

options.log("Submitting Put Blob request for " + id);
promises[id] = {resolve: resolve, reject: reject};
endpoints[id] = url;

promises[id] = promise;
endpoints[id] = url;

requester.initTransport(id)
.withPayload(file)
.withHeaders({"Content-Type": file.type})
.send(xhr);

return promise;
requester.initTransport(id)
.withPayload(file)
.withHeaders({"Content-Type": file.type})
.send(xhr);
});
}
});
};
Loading