app/assets/javascripts/condo/amazon.js in condo-1.0.0 vs app/assets/javascripts/condo/amazon.js in condo-1.0.1
- old
+ new
@@ -16,24 +16,19 @@
**/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
- define(['jquery', 'spark-md5', 'base64', 'condo_uploader'], factory);
+ define(['jquery', 'base64', 'condo-uploader'], factory);
} else {
// Browser globals
- factory(jQuery, window.SparkMD5, window.base64, window.CondoUploader);
+ factory(jQuery, window.base64);
}
-}(function ($, MD5, base64, uploads, undefined) {
+}(function ($, base64) {
'use strict';
- //
- // TODO:: Create an Amazon, google factory etc
- // We should split all these into different files too (controller and factories separate from directives and views)
- // So we can have different views for the same controller
- //
- uploads.factory('Condo.AmazonS3', ['$rootScope', '$q', function($rootScope, $q) {
+ angular.module('CondoAmazonProvider', ['CondoUploader', 'CondoAbstractMd5']).run(['$q', 'Condo.Registrar', 'Condo.Md5', function($q, registrar, md5) {
var PENDING = 0,
STARTED = 1,
PAUSED = 2,
UPLOADING = 3,
COMPLETED = 4,
@@ -80,47 +75,32 @@
//
// We need to sign our uploads so amazon can confirm they are valid for us
// Part numbers can be any number from 1 to 10,000 - inclusive
- // TODO:: use http://updates.html5rocks.com/2011/12/Transferable-Objects-Lightning-Fast
- // where available :)
//
build_request = function(part_number) {
- var result = $q.defer(),
- reader = new FileReader(),
- fail = function(){
- result.reject('file read failed');
- },
- current_part;
+ var current_part;
if (file.size > part_size) { // If file bigger then 5mb we expect a chunked upload
var endbyte = part_number * part_size;
if (endbyte > file.size)
endbyte = file.size;
current_part = file.slice((part_number - 1) * part_size, endbyte);
} else {
current_part = file;
}
- reader.onload = function(e) {
- result.resolve({
+ return md5.hash(current_part).then(function(val) {
+ return {
data: current_part,
- data_id: MD5.hashBinary(e.target.result),
+ data_id: val,
part_number: part_number
- });
-
-
- if(!$rootScope.$$phase) {
- $rootScope.$apply(); // This triggers the promise response if required
}
- };
- reader.onerror = fail;
- reader.onabort = fail;
- reader.readAsBinaryString(current_part);
-
- return result.promise;
+ }, function(reason){
+ return $q.reject(reason);
+ });
},
//
// Direct file upload strategy
//
@@ -410,14 +390,17 @@
}
};
}; // END AMAZON
- return {
+ //
+ // Register the residence with the API
+ // Dependency injection succeeded
+ //
+ registrar.register('AmazonS3', {
new_upload: function(api, file) {
return new Amazon(api, file);
}
- };
-
+ });
}]);
}));