summaryrefslogtreecommitdiffstats
path: root/web/react/utils
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-08-11 12:08:08 -0400
committerChristopher Speller <crspeller@gmail.com>2015-08-11 12:08:08 -0400
commit4c7cdb20f074e2c06a08cd64a57060b8e8b64d2e (patch)
treefd5e1948bc5f24cd8711a7a6681b142745228025 /web/react/utils
parentd72d356cbcb027df8b2fcd3c84e26b64119e6b5c (diff)
parent17b05f705f910429ece1ca6c64ec56bf89dd014b (diff)
downloadchat-4c7cdb20f074e2c06a08cd64a57060b8e8b64d2e.tar.gz
chat-4c7cdb20f074e2c06a08cd64a57060b8e8b64d2e.tar.bz2
chat-4c7cdb20f074e2c06a08cd64a57060b8e8b64d2e.zip
Merge pull request #359 from hmhealey/mm1770
MM-1770 Add the ability to cancel in-progress file uploads
Diffstat (limited to 'web/react/utils')
-rw-r--r--web/react/utils/client.jsx10
-rw-r--r--web/react/utils/utils.jsx21
2 files changed, 28 insertions, 3 deletions
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx
index 3375da7cf..6a1f7c820 100644
--- a/web/react/utils/client.jsx
+++ b/web/react/utils/client.jsx
@@ -754,7 +754,7 @@ module.exports.getProfiles = function(success, error) {
};
module.exports.uploadFile = function(formData, success, error) {
- $.ajax({
+ var request = $.ajax({
url: "/api/v1/files/upload",
type: 'POST',
data: formData,
@@ -763,12 +763,16 @@ module.exports.uploadFile = function(formData, success, error) {
processData: false,
success: success,
error: function(xhr, status, err) {
- e = handleError("uploadFile", xhr, status, err);
- error(e);
+ if (err !== 'abort') {
+ e = handleError("uploadFile", xhr, status, err);
+ error(e);
+ }
}
});
module.exports.track('api', 'api_files_upload');
+
+ return request;
};
module.exports.getPublicLink = function(data, success, error) {
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index a759cc579..2214b6239 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -913,3 +913,24 @@ module.exports.getFileName = function(path) {
var split = path.split('/');
return split[split.length - 1];
};
+
+// Generates a RFC-4122 version 4 compliant globally unique identifier.
+module.exports.generateId = function() {
+ // implementation taken from http://stackoverflow.com/a/2117523
+ var id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
+
+ id = id.replace(/[xy]/g, function(c) {
+ var r = Math.floor(Math.random() * 16);
+
+ var v;
+ if (c === 'x') {
+ v = r;
+ } else {
+ v = r & 0x3 | 0x8;
+ }
+
+ return v.toString(16);
+ });
+
+ return id;
+};