From 4e8af44370bfb4276e009526045a4983d5ff245a Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 10 Aug 2015 08:41:18 -0400 Subject: Added the ability to cancel file uploads on posts --- web/react/utils/client.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'web/react/utils') diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index b8eda0075..d979515ef 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -762,7 +762,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, @@ -771,12 +771,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) { -- cgit v1.2.3-1-g7c22 From c9a1bf2d336cc5718cdf327f37cfdf87dc0e2705 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 10 Aug 2015 12:05:45 -0400 Subject: Changed post drafts to maintain a store a unique id for each file upload to fix issues with duplicate file names --- web/react/utils/utils.jsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'web/react/utils') 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; +}; -- cgit v1.2.3-1-g7c22