app/assets/javascripts/condo/amazon.js in condo-0.0.1 vs app/assets/javascripts/condo/amazon.js in condo-1.0.0

- old
+ new

@@ -58,11 +58,14 @@ Amazon = function (api, file) { var self = this, strategy = null, part_size = 5242880, // Multi-part uploads should be bigger then this + pausing = false, defaultError = function(reason) { + self.error = !pausing; + pausing = false; self.pause(reason); }, restart = function() { strategy = null; @@ -208,13 +211,11 @@ api.edit(part_number, base64.encode(hexToBin(result.data_id))). then(function(data) { set_part(data, result); }, defaultError); - }, function(reason){ - self.pause(reason); - }); // END BUILD_REQUEST + }, defaultError); // END BUILD_REQUEST } else { // // We're after the final commit // @@ -305,21 +306,33 @@ this.state = PENDING; this.progress = 0; this.message = 'pending'; this.name = file.name; this.size = file.size; + this.error = false; // + // File path is optional (amazon supports paths as part of the key name) + // http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/ListingKeysHierarchy.html + // + if(!!file.dir_path) + this.path = file.dir_path; + + + // // Support file slicing // if (typeof(file.slice) != 'function') file.slice = file.webkitSlice || file.mozSlice; this.start = function(){ if(strategy == null) { // We need to create the upload + self.error = false; + pausing = false; + // // Update part size if required // if((part_size * 9999) < file.size) { part_size = file.size / 9999; @@ -344,23 +357,24 @@ } else { strategy = new AmazonChunked(data, result); } }, defaultError); - }, function(reason){ - self.pause(reason); - }); // END BUILD_REQUEST + }, defaultError); // END BUILD_REQUEST } else if (this.state == PAUSED) { // We need to resume the upload if it is paused this.message = null; + self.error = false; + pausing = false; strategy.resume(); } }; this.pause = function(reason) { if(strategy != null && this.state == UPLOADING) { // Check if the upload is uploading this.state = PAUSED; + pausing = true; strategy.pause(); } else if (this.state <= STARTED) { this.state = PAUSED; restart(); }