activestorage 5.2.1 → 5.2.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activestorage might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3cb1f60951d79219c1e3b4424ffd1c4b50678c70a24dca0c1a4a015ea468802
4
- data.tar.gz: 830ffc76e9876db10f3e7dcba276b20c41c5d83ed8afbd210334811cf71ddbf8
3
+ metadata.gz: 5e02ba426092f1e20174bcd0c0c98e286d1fdc81e65e9d6ee9834857537296ec
4
+ data.tar.gz: ea42d90a9b3366b69ddd765493b9969414a734e88825ec7722f899579be002aa
5
5
  SHA512:
6
- metadata.gz: e94e32e5bf798b0d4313ae66d7cbb60c381997d76980e387e671c6977ee2738f31b6cfc8f37f9ccf1e1f455d7b6261455359811ed1877d5a49214d22f1dca1cb
7
- data.tar.gz: cef3b437d62a555be6bbc2681c81429099661108042dcc1030a3af51a9590165487c78fadffdec0481f7b2559b68dc53f4a2a034b13e8868cd4efe34d0fcc9c5
6
+ metadata.gz: 8a04ba736562747df568ee7b03064445e8623e2b3e45c91cab616f64dfbaa2f4565903df14d324cb41e1a467ff55ccc9b407b75a1e7be28525c46c4238e1e6db
7
+ data.tar.gz: '0794a810c03f4b6e8d2c1326764fc4157a2f66bc196cdccf6cae7dd28744382abc0d24c89aedf7e7ca03e5c7175036bdd21ce2fb208523592b10fe6fbe92978b'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,89 @@
1
+ ## Rails 5.2.5 (March 26, 2021) ##
2
+
3
+ * Marcel is upgraded to version 1.0.0 to avoid a dependency on GPL-licensed
4
+ mime types data.
5
+
6
+ *George Claghorn*
7
+
8
+ * The Poppler PDF previewer renders a preview image using the original
9
+ document's crop box rather than its media box, hiding print margins. This
10
+ matches the behavior of the MuPDF previewer.
11
+
12
+ *Vincent Robert*
13
+
14
+
15
+ ## Rails 5.2.4.5 (February 10, 2021) ##
16
+
17
+ * No changes.
18
+
19
+
20
+ ## Rails 5.2.4.4 (September 09, 2020) ##
21
+
22
+ * No changes.
23
+
24
+
25
+ ## Rails 5.2.4.3 (May 18, 2020) ##
26
+
27
+ * [CVE-2020-8162] Include Content-Length in signature for ActiveStorage direct upload
28
+
29
+
30
+ ## Rails 5.2.4.2 (March 19, 2020) ##
31
+
32
+ * No changes.
33
+
34
+
35
+ ## Rails 5.2.4.1 (December 18, 2019) ##
36
+
37
+ * No changes.
38
+
39
+
40
+ ## Rails 5.2.4 (November 27, 2019) ##
41
+
42
+ * No changes.
43
+
44
+
45
+ ## Rails 5.2.3 (March 27, 2019) ##
46
+
47
+ * No changes.
48
+
49
+
50
+ ## Rails 5.2.2.1 (March 11, 2019) ##
51
+
52
+ * No changes.
53
+
54
+
55
+ ## Rails 5.2.2 (December 04, 2018) ##
56
+
57
+ * Support multiple submit buttons in Active Storage forms.
58
+
59
+ *Chrıs Seelus*
60
+
61
+ * Fix `ArgumentError` when uploading to amazon s3
62
+
63
+ *Hiroki Sanpei*
64
+
65
+ * Add a foreign-key constraint to the `active_storage_attachments` table for blobs.
66
+
67
+ *George Claghorn*
68
+
69
+ * Discard `ActiveStorage::PurgeJobs` for missing blobs.
70
+
71
+ *George Claghorn*
72
+
73
+ * Fix uploading Tempfiles to Azure Storage.
74
+
75
+ *George Claghorn*
76
+
77
+
78
+ ## Rails 5.2.1.1 (November 27, 2018) ##
79
+
80
+ * Prevent content type and disposition bypass in storage service URLs.
81
+
82
+ Fix CVE-2018-16477.
83
+
84
+ *Rosa Gutierrez*
85
+
86
+
1
87
  ## Rails 5.2.1 (August 07, 2018) ##
2
88
 
3
89
  * Fix direct upload with zero-byte files.
@@ -1 +1,939 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ActiveStorage=e():t.ActiveStorage=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,r){"use strict";function n(t){var e=a(document.head,'meta[name="'+t+'"]');if(e)return e.getAttribute("content")}function i(t,e){return"string"==typeof t&&(e=t,t=document),o(t.querySelectorAll(e))}function a(t,e){return"string"==typeof t&&(e=t,t=document),t.querySelector(e)}function u(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=t.disabled,i=r.bubbles,a=r.cancelable,u=r.detail,o=document.createEvent("Event");o.initEvent(e,i||!0,a||!0),o.detail=u||{};try{t.disabled=!1,t.dispatchEvent(o)}finally{t.disabled=n}return o}function o(t){return Array.isArray(t)?t:Array.from?Array.from(t):[].slice.call(t)}e.d=n,e.c=i,e.b=a,e.a=u,e.e=o},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(t&&"function"==typeof t[e]){for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];return t[e].apply(t,n)}}r.d(e,"a",function(){return c});var a=r(6),u=r(8),o=r(9),s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),f=0,c=function(){function t(e,r,i){n(this,t),this.id=++f,this.file=e,this.url=r,this.delegate=i}return s(t,[{key:"create",value:function(t){var e=this;a.a.create(this.file,function(r,n){if(r)return void t(r);var a=new u.a(e.file,n,e.url);i(e.delegate,"directUploadWillCreateBlobWithXHR",a.xhr),a.create(function(r){if(r)t(r);else{var n=new o.a(a);i(e.delegate,"directUploadWillStoreFileWithXHR",n.xhr),n.create(function(e){e?t(e):t(null,a.toJSON())})}})})}}]),t}()},function(t,e,r){"use strict";function n(){window.ActiveStorage&&Object(i.a)()}Object.defineProperty(e,"__esModule",{value:!0});var i=r(3),a=r(1);r.d(e,"start",function(){return i.a}),r.d(e,"DirectUpload",function(){return a.a}),setTimeout(n,1)},function(t,e,r){"use strict";function n(){d||(d=!0,document.addEventListener("submit",i),document.addEventListener("ajax:before",a))}function i(t){u(t)}function a(t){"FORM"==t.target.tagName&&u(t)}function u(t){var e=t.target;if(e.hasAttribute(l))return void t.preventDefault();var r=new c.a(e),n=r.inputs;n.length&&(t.preventDefault(),e.setAttribute(l,""),n.forEach(s),r.start(function(t){e.removeAttribute(l),t?n.forEach(f):o(e)}))}function o(t){var e=Object(h.b)(t,"input[type=submit]");if(e){var r=e,n=r.disabled;e.disabled=!1,e.focus(),e.click(),e.disabled=n}else e=document.createElement("input"),e.type="submit",e.style.display="none",t.appendChild(e),e.click(),t.removeChild(e)}function s(t){t.disabled=!0}function f(t){t.disabled=!1}e.a=n;var c=r(4),h=r(0),l="data-direct-uploads-processing",d=!1},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}r.d(e,"a",function(){return s});var i=r(5),a=r(0),u=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o="input[type=file][data-direct-upload-url]:not([disabled])",s=function(){function t(e){n(this,t),this.form=e,this.inputs=Object(a.c)(e,o).filter(function(t){return t.files.length})}return u(t,[{key:"start",value:function(t){var e=this,r=this.createDirectUploadControllers();this.dispatch("start"),function n(){var i=r.shift();i?i.start(function(r){r?(t(r),e.dispatch("end")):n()}):(t(),e.dispatch("end"))}()}},{key:"createDirectUploadControllers",value:function(){var t=[];return this.inputs.forEach(function(e){Object(a.e)(e.files).forEach(function(r){var n=new i.a(e,r);t.push(n)})}),t}},{key:"dispatch",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Object(a.a)(this.form,"direct-uploads:"+t,{detail:e})}}]),t}()},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}r.d(e,"a",function(){return o});var i=r(1),a=r(0),u=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(e,r){n(this,t),this.input=e,this.file=r,this.directUpload=new i.a(this.file,this.url,this),this.dispatch("initialize")}return u(t,[{key:"start",value:function(t){var e=this,r=document.createElement("input");r.type="hidden",r.name=this.input.name,this.input.insertAdjacentElement("beforebegin",r),this.dispatch("start"),this.directUpload.create(function(n,i){n?(r.parentNode.removeChild(r),e.dispatchError(n)):r.value=i.signed_id,e.dispatch("end"),t(n)})}},{key:"uploadRequestDidProgress",value:function(t){var e=t.loaded/t.total*100;e&&this.dispatch("progress",{progress:e})}},{key:"dispatch",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.file=this.file,e.id=this.directUpload.id,Object(a.a)(this.input,"direct-upload:"+t,{detail:e})}},{key:"dispatchError",value:function(t){this.dispatch("error",{error:t}).defaultPrevented||alert(t)}},{key:"directUploadWillCreateBlobWithXHR",value:function(t){this.dispatch("before-blob-request",{xhr:t})}},{key:"directUploadWillStoreFileWithXHR",value:function(t){var e=this;this.dispatch("before-storage-request",{xhr:t}),t.upload.addEventListener("progress",function(t){return e.uploadRequestDidProgress(t)})}},{key:"url",get:function(){return this.input.getAttribute("data-direct-upload-url")}}]),t}()},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}r.d(e,"a",function(){return s});var i=r(7),a=r.n(i),u=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,s=function(){function t(e){n(this,t),this.file=e,this.chunkSize=2097152,this.chunkCount=Math.ceil(this.file.size/this.chunkSize),this.chunkIndex=0}return u(t,null,[{key:"create",value:function(e,r){new t(e).create(r)}}]),u(t,[{key:"create",value:function(t){var e=this;this.callback=t,this.md5Buffer=new a.a.ArrayBuffer,this.fileReader=new FileReader,this.fileReader.addEventListener("load",function(t){return e.fileReaderDidLoad(t)}),this.fileReader.addEventListener("error",function(t){return e.fileReaderDidError(t)}),this.readNextChunk()}},{key:"fileReaderDidLoad",value:function(t){if(this.md5Buffer.append(t.target.result),!this.readNextChunk()){var e=this.md5Buffer.end(!0),r=btoa(e);this.callback(null,r)}}},{key:"fileReaderDidError",value:function(t){this.callback("Error reading "+this.file.name)}},{key:"readNextChunk",value:function(){if(this.chunkIndex<this.chunkCount||0==this.chunkIndex&&0==this.chunkCount){var t=this.chunkIndex*this.chunkSize,e=Math.min(t+this.chunkSize,this.file.size),r=o.call(this.file,t,e);return this.fileReader.readAsArrayBuffer(r),this.chunkIndex++,!0}return!1}}]),t}()},function(t,e,r){!function(e){t.exports=e()}(function(t){"use strict";function e(t,e){var r=t[0],n=t[1],i=t[2],a=t[3];r+=(n&i|~n&a)+e[0]-680876936|0,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[1]-389564586|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[2]+606105819|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[3]-1044525330|0,n=(n<<22|n>>>10)+i|0,r+=(n&i|~n&a)+e[4]-176418897|0,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[5]+1200080426|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[6]-1473231341|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[7]-45705983|0,n=(n<<22|n>>>10)+i|0,r+=(n&i|~n&a)+e[8]+1770035416|0,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[9]-1958414417|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[10]-42063|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[11]-1990404162|0,n=(n<<22|n>>>10)+i|0,r+=(n&i|~n&a)+e[12]+1804603682|0,r=(r<<7|r>>>25)+n|0,a+=(r&n|~r&i)+e[13]-40341101|0,a=(a<<12|a>>>20)+r|0,i+=(a&r|~a&n)+e[14]-1502002290|0,i=(i<<17|i>>>15)+a|0,n+=(i&a|~i&r)+e[15]+1236535329|0,n=(n<<22|n>>>10)+i|0,r+=(n&a|i&~a)+e[1]-165796510|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[6]-1069501632|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[11]+643717713|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[0]-373897302|0,n=(n<<20|n>>>12)+i|0,r+=(n&a|i&~a)+e[5]-701558691|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[10]+38016083|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[15]-660478335|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[4]-405537848|0,n=(n<<20|n>>>12)+i|0,r+=(n&a|i&~a)+e[9]+568446438|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[14]-1019803690|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[3]-187363961|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[8]+1163531501|0,n=(n<<20|n>>>12)+i|0,r+=(n&a|i&~a)+e[13]-1444681467|0,r=(r<<5|r>>>27)+n|0,a+=(r&i|n&~i)+e[2]-51403784|0,a=(a<<9|a>>>23)+r|0,i+=(a&n|r&~n)+e[7]+1735328473|0,i=(i<<14|i>>>18)+a|0,n+=(i&r|a&~r)+e[12]-1926607734|0,n=(n<<20|n>>>12)+i|0,r+=(n^i^a)+e[5]-378558|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[8]-2022574463|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[11]+1839030562|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[14]-35309556|0,n=(n<<23|n>>>9)+i|0,r+=(n^i^a)+e[1]-1530992060|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[4]+1272893353|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[7]-155497632|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[10]-1094730640|0,n=(n<<23|n>>>9)+i|0,r+=(n^i^a)+e[13]+681279174|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[0]-358537222|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[3]-722521979|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[6]+76029189|0,n=(n<<23|n>>>9)+i|0,r+=(n^i^a)+e[9]-640364487|0,r=(r<<4|r>>>28)+n|0,a+=(r^n^i)+e[12]-421815835|0,a=(a<<11|a>>>21)+r|0,i+=(a^r^n)+e[15]+530742520|0,i=(i<<16|i>>>16)+a|0,n+=(i^a^r)+e[2]-995338651|0,n=(n<<23|n>>>9)+i|0,r+=(i^(n|~a))+e[0]-198630844|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[7]+1126891415|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[14]-1416354905|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[5]-57434055|0,n=(n<<21|n>>>11)+i|0,r+=(i^(n|~a))+e[12]+1700485571|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[3]-1894986606|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[10]-1051523|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[1]-2054922799|0,n=(n<<21|n>>>11)+i|0,r+=(i^(n|~a))+e[8]+1873313359|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[15]-30611744|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[6]-1560198380|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[13]+1309151649|0,n=(n<<21|n>>>11)+i|0,r+=(i^(n|~a))+e[4]-145523070|0,r=(r<<6|r>>>26)+n|0,a+=(n^(r|~i))+e[11]-1120210379|0,a=(a<<10|a>>>22)+r|0,i+=(r^(a|~n))+e[2]+718787259|0,i=(i<<15|i>>>17)+a|0,n+=(a^(i|~r))+e[9]-343485551|0,n=(n<<21|n>>>11)+i|0,t[0]=r+t[0]|0,t[1]=n+t[1]|0,t[2]=i+t[2]|0,t[3]=a+t[3]|0}function r(t){var e,r=[];for(e=0;e<64;e+=4)r[e>>2]=t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24);return r}function n(t){var e,r=[];for(e=0;e<64;e+=4)r[e>>2]=t[e]+(t[e+1]<<8)+(t[e+2]<<16)+(t[e+3]<<24);return r}function i(t){var n,i,a,u,o,s,f=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(n=64;n<=f;n+=64)e(c,r(t.substring(n-64,n)));for(t=t.substring(n-64),i=t.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<i;n+=1)a[n>>2]|=t.charCodeAt(n)<<(n%4<<3);if(a[n>>2]|=128<<(n%4<<3),n>55)for(e(c,a),n=0;n<16;n+=1)a[n]=0;return u=8*f,u=u.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(u[2],16),s=parseInt(u[1],16)||0,a[14]=o,a[15]=s,e(c,a),c}function a(t){var r,i,a,u,o,s,f=t.length,c=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=f;r+=64)e(c,n(t.subarray(r-64,r)));for(t=r-64<f?t.subarray(r-64):new Uint8Array(0),i=t.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<i;r+=1)a[r>>2]|=t[r]<<(r%4<<3);if(a[r>>2]|=128<<(r%4<<3),r>55)for(e(c,a),r=0;r<16;r+=1)a[r]=0;return u=8*f,u=u.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(u[2],16),s=parseInt(u[1],16)||0,a[14]=o,a[15]=s,e(c,a),c}function u(t){var e,r="";for(e=0;e<4;e+=1)r+=p[t>>8*e+4&15]+p[t>>8*e&15];return r}function o(t){var e;for(e=0;e<t.length;e+=1)t[e]=u(t[e]);return t.join("")}function s(t){return/[\u0080-\uFFFF]/.test(t)&&(t=unescape(encodeURIComponent(t))),t}function f(t,e){var r,n=t.length,i=new ArrayBuffer(n),a=new Uint8Array(i);for(r=0;r<n;r+=1)a[r]=t.charCodeAt(r);return e?a:i}function c(t){return String.fromCharCode.apply(null,new Uint8Array(t))}function h(t,e,r){var n=new Uint8Array(t.byteLength+e.byteLength);return n.set(new Uint8Array(t)),n.set(new Uint8Array(e),t.byteLength),r?n:n.buffer}function l(t){var e,r=[],n=t.length;for(e=0;e<n-1;e+=2)r.push(parseInt(t.substr(e,2),16));return String.fromCharCode.apply(String,r)}function d(){this.reset()}var p=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return"5d41402abc4b2a76b9719d911017c592"!==o(i("hello"))&&function(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r},"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function e(t,e){return t=0|t||0,t<0?Math.max(t+e,0):Math.min(t,e)}ArrayBuffer.prototype.slice=function(r,n){var i,a,u,o,s=this.byteLength,f=e(r,s),c=s;return n!==t&&(c=e(n,s)),f>c?new ArrayBuffer(0):(i=c-f,a=new ArrayBuffer(i),u=new Uint8Array(a),o=new Uint8Array(this,f,i),u.set(o),a)}}(),d.prototype.append=function(t){return this.appendBinary(s(t)),this},d.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var n,i=this._buff.length;for(n=64;n<=i;n+=64)e(this._hash,r(this._buff.substring(n-64,n)));return this._buff=this._buff.substring(n-64),this},d.prototype.end=function(t){var e,r,n=this._buff,i=n.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;e<i;e+=1)a[e>>2]|=n.charCodeAt(e)<<(e%4<<3);return this._finish(a,i),r=o(this._hash),t&&(r=l(r)),this.reset(),r},d.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},d.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},d.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},d.prototype._finish=function(t,r){var n,i,a,u=r;if(t[u>>2]|=128<<(u%4<<3),u>55)for(e(this._hash,t),u=0;u<16;u+=1)t[u]=0;n=8*this._length,n=n.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(n[2],16),a=parseInt(n[1],16)||0,t[14]=i,t[15]=a,e(this._hash,t)},d.hash=function(t,e){return d.hashBinary(s(t),e)},d.hashBinary=function(t,e){var r=i(t),n=o(r);return e?l(n):n},d.ArrayBuffer=function(){this.reset()},d.ArrayBuffer.prototype.append=function(t){var r,i=h(this._buff.buffer,t,!0),a=i.length;for(this._length+=t.byteLength,r=64;r<=a;r+=64)e(this._hash,n(i.subarray(r-64,r)));return this._buff=r-64<a?new Uint8Array(i.buffer.slice(r-64)):new Uint8Array(0),this},d.ArrayBuffer.prototype.end=function(t){var e,r,n=this._buff,i=n.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;e<i;e+=1)a[e>>2]|=n[e]<<(e%4<<3);return this._finish(a,i),r=o(this._hash),t&&(r=l(r)),this.reset(),r},d.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.ArrayBuffer.prototype.getState=function(){var t=d.prototype.getState.call(this);return t.buff=c(t.buff),t},d.ArrayBuffer.prototype.setState=function(t){return t.buff=f(t.buff,!0),d.prototype.setState.call(this,t)},d.ArrayBuffer.prototype.destroy=d.prototype.destroy,d.ArrayBuffer.prototype._finish=d.prototype._finish,d.ArrayBuffer.hash=function(t,e){var r=a(new Uint8Array(t)),n=o(r);return e?l(n):n},d})},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}r.d(e,"a",function(){return u});var i=r(0),a=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),u=function(){function t(e,r,a){var u=this;n(this,t),this.file=e,this.attributes={filename:e.name,content_type:e.type,byte_size:e.size,checksum:r},this.xhr=new XMLHttpRequest,this.xhr.open("POST",a,!0),this.xhr.responseType="json",this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.setRequestHeader("Accept","application/json"),this.xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"),this.xhr.setRequestHeader("X-CSRF-Token",Object(i.d)("csrf-token")),this.xhr.addEventListener("load",function(t){return u.requestDidLoad(t)}),this.xhr.addEventListener("error",function(t){return u.requestDidError(t)})}return a(t,[{key:"create",value:function(t){this.callback=t,this.xhr.send(JSON.stringify({blob:this.attributes}))}},{key:"requestDidLoad",value:function(t){if(this.status>=200&&this.status<300){var e=this.response,r=e.direct_upload;delete e.direct_upload,this.attributes=e,this.directUploadData=r,this.callback(null,this.toJSON())}else this.requestDidError(t)}},{key:"requestDidError",value:function(t){this.callback('Error creating Blob for "'+this.file.name+'". Status: '+this.status)}},{key:"toJSON",value:function(){var t={};for(var e in this.attributes)t[e]=this.attributes[e];return t}},{key:"status",get:function(){return this.xhr.status}},{key:"response",get:function(){var t=this.xhr,e=t.responseType,r=t.response;return"json"==e?r:JSON.parse(r)}}]),t}()},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}r.d(e,"a",function(){return a});var i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),a=function(){function t(e){var r=this;n(this,t),this.blob=e,this.file=e.file;var i=e.directUploadData,a=i.url,u=i.headers;this.xhr=new XMLHttpRequest,this.xhr.open("PUT",a,!0),this.xhr.responseType="text";for(var o in u)this.xhr.setRequestHeader(o,u[o]);this.xhr.addEventListener("load",function(t){return r.requestDidLoad(t)}),this.xhr.addEventListener("error",function(t){return r.requestDidError(t)})}return i(t,[{key:"create",value:function(t){this.callback=t,this.xhr.send(this.file.slice())}},{key:"requestDidLoad",value:function(t){var e=this.xhr,r=e.status,n=e.response;r>=200&&r<300?this.callback(null,n):this.requestDidError(t)}},{key:"requestDidError",value:function(t){this.callback('Error storing "'+this.file.name+'". Status: '+this.xhr.status)}}]),t}()}])});
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define([ "exports" ], factory) : factory(global.ActiveStorage = {});
3
+ })(this, function(exports) {
4
+ "use strict";
5
+ function createCommonjsModule(fn, module) {
6
+ return module = {
7
+ exports: {}
8
+ }, fn(module, module.exports), module.exports;
9
+ }
10
+ var sparkMd5 = createCommonjsModule(function(module, exports) {
11
+ (function(factory) {
12
+ {
13
+ module.exports = factory();
14
+ }
15
+ })(function(undefined) {
16
+ var hex_chr = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ];
17
+ function md5cycle(x, k) {
18
+ var a = x[0], b = x[1], c = x[2], d = x[3];
19
+ a += (b & c | ~b & d) + k[0] - 680876936 | 0;
20
+ a = (a << 7 | a >>> 25) + b | 0;
21
+ d += (a & b | ~a & c) + k[1] - 389564586 | 0;
22
+ d = (d << 12 | d >>> 20) + a | 0;
23
+ c += (d & a | ~d & b) + k[2] + 606105819 | 0;
24
+ c = (c << 17 | c >>> 15) + d | 0;
25
+ b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
26
+ b = (b << 22 | b >>> 10) + c | 0;
27
+ a += (b & c | ~b & d) + k[4] - 176418897 | 0;
28
+ a = (a << 7 | a >>> 25) + b | 0;
29
+ d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
30
+ d = (d << 12 | d >>> 20) + a | 0;
31
+ c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
32
+ c = (c << 17 | c >>> 15) + d | 0;
33
+ b += (c & d | ~c & a) + k[7] - 45705983 | 0;
34
+ b = (b << 22 | b >>> 10) + c | 0;
35
+ a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
36
+ a = (a << 7 | a >>> 25) + b | 0;
37
+ d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
38
+ d = (d << 12 | d >>> 20) + a | 0;
39
+ c += (d & a | ~d & b) + k[10] - 42063 | 0;
40
+ c = (c << 17 | c >>> 15) + d | 0;
41
+ b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
42
+ b = (b << 22 | b >>> 10) + c | 0;
43
+ a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
44
+ a = (a << 7 | a >>> 25) + b | 0;
45
+ d += (a & b | ~a & c) + k[13] - 40341101 | 0;
46
+ d = (d << 12 | d >>> 20) + a | 0;
47
+ c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
48
+ c = (c << 17 | c >>> 15) + d | 0;
49
+ b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
50
+ b = (b << 22 | b >>> 10) + c | 0;
51
+ a += (b & d | c & ~d) + k[1] - 165796510 | 0;
52
+ a = (a << 5 | a >>> 27) + b | 0;
53
+ d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
54
+ d = (d << 9 | d >>> 23) + a | 0;
55
+ c += (d & b | a & ~b) + k[11] + 643717713 | 0;
56
+ c = (c << 14 | c >>> 18) + d | 0;
57
+ b += (c & a | d & ~a) + k[0] - 373897302 | 0;
58
+ b = (b << 20 | b >>> 12) + c | 0;
59
+ a += (b & d | c & ~d) + k[5] - 701558691 | 0;
60
+ a = (a << 5 | a >>> 27) + b | 0;
61
+ d += (a & c | b & ~c) + k[10] + 38016083 | 0;
62
+ d = (d << 9 | d >>> 23) + a | 0;
63
+ c += (d & b | a & ~b) + k[15] - 660478335 | 0;
64
+ c = (c << 14 | c >>> 18) + d | 0;
65
+ b += (c & a | d & ~a) + k[4] - 405537848 | 0;
66
+ b = (b << 20 | b >>> 12) + c | 0;
67
+ a += (b & d | c & ~d) + k[9] + 568446438 | 0;
68
+ a = (a << 5 | a >>> 27) + b | 0;
69
+ d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
70
+ d = (d << 9 | d >>> 23) + a | 0;
71
+ c += (d & b | a & ~b) + k[3] - 187363961 | 0;
72
+ c = (c << 14 | c >>> 18) + d | 0;
73
+ b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
74
+ b = (b << 20 | b >>> 12) + c | 0;
75
+ a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
76
+ a = (a << 5 | a >>> 27) + b | 0;
77
+ d += (a & c | b & ~c) + k[2] - 51403784 | 0;
78
+ d = (d << 9 | d >>> 23) + a | 0;
79
+ c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
80
+ c = (c << 14 | c >>> 18) + d | 0;
81
+ b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
82
+ b = (b << 20 | b >>> 12) + c | 0;
83
+ a += (b ^ c ^ d) + k[5] - 378558 | 0;
84
+ a = (a << 4 | a >>> 28) + b | 0;
85
+ d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
86
+ d = (d << 11 | d >>> 21) + a | 0;
87
+ c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
88
+ c = (c << 16 | c >>> 16) + d | 0;
89
+ b += (c ^ d ^ a) + k[14] - 35309556 | 0;
90
+ b = (b << 23 | b >>> 9) + c | 0;
91
+ a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
92
+ a = (a << 4 | a >>> 28) + b | 0;
93
+ d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
94
+ d = (d << 11 | d >>> 21) + a | 0;
95
+ c += (d ^ a ^ b) + k[7] - 155497632 | 0;
96
+ c = (c << 16 | c >>> 16) + d | 0;
97
+ b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
98
+ b = (b << 23 | b >>> 9) + c | 0;
99
+ a += (b ^ c ^ d) + k[13] + 681279174 | 0;
100
+ a = (a << 4 | a >>> 28) + b | 0;
101
+ d += (a ^ b ^ c) + k[0] - 358537222 | 0;
102
+ d = (d << 11 | d >>> 21) + a | 0;
103
+ c += (d ^ a ^ b) + k[3] - 722521979 | 0;
104
+ c = (c << 16 | c >>> 16) + d | 0;
105
+ b += (c ^ d ^ a) + k[6] + 76029189 | 0;
106
+ b = (b << 23 | b >>> 9) + c | 0;
107
+ a += (b ^ c ^ d) + k[9] - 640364487 | 0;
108
+ a = (a << 4 | a >>> 28) + b | 0;
109
+ d += (a ^ b ^ c) + k[12] - 421815835 | 0;
110
+ d = (d << 11 | d >>> 21) + a | 0;
111
+ c += (d ^ a ^ b) + k[15] + 530742520 | 0;
112
+ c = (c << 16 | c >>> 16) + d | 0;
113
+ b += (c ^ d ^ a) + k[2] - 995338651 | 0;
114
+ b = (b << 23 | b >>> 9) + c | 0;
115
+ a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
116
+ a = (a << 6 | a >>> 26) + b | 0;
117
+ d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
118
+ d = (d << 10 | d >>> 22) + a | 0;
119
+ c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
120
+ c = (c << 15 | c >>> 17) + d | 0;
121
+ b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
122
+ b = (b << 21 | b >>> 11) + c | 0;
123
+ a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
124
+ a = (a << 6 | a >>> 26) + b | 0;
125
+ d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
126
+ d = (d << 10 | d >>> 22) + a | 0;
127
+ c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
128
+ c = (c << 15 | c >>> 17) + d | 0;
129
+ b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
130
+ b = (b << 21 | b >>> 11) + c | 0;
131
+ a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
132
+ a = (a << 6 | a >>> 26) + b | 0;
133
+ d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
134
+ d = (d << 10 | d >>> 22) + a | 0;
135
+ c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
136
+ c = (c << 15 | c >>> 17) + d | 0;
137
+ b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
138
+ b = (b << 21 | b >>> 11) + c | 0;
139
+ a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
140
+ a = (a << 6 | a >>> 26) + b | 0;
141
+ d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
142
+ d = (d << 10 | d >>> 22) + a | 0;
143
+ c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
144
+ c = (c << 15 | c >>> 17) + d | 0;
145
+ b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
146
+ b = (b << 21 | b >>> 11) + c | 0;
147
+ x[0] = a + x[0] | 0;
148
+ x[1] = b + x[1] | 0;
149
+ x[2] = c + x[2] | 0;
150
+ x[3] = d + x[3] | 0;
151
+ }
152
+ function md5blk(s) {
153
+ var md5blks = [], i;
154
+ for (i = 0; i < 64; i += 4) {
155
+ md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
156
+ }
157
+ return md5blks;
158
+ }
159
+ function md5blk_array(a) {
160
+ var md5blks = [], i;
161
+ for (i = 0; i < 64; i += 4) {
162
+ md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
163
+ }
164
+ return md5blks;
165
+ }
166
+ function md51(s) {
167
+ var n = s.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;
168
+ for (i = 64; i <= n; i += 64) {
169
+ md5cycle(state, md5blk(s.substring(i - 64, i)));
170
+ }
171
+ s = s.substring(i - 64);
172
+ length = s.length;
173
+ tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
174
+ for (i = 0; i < length; i += 1) {
175
+ tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);
176
+ }
177
+ tail[i >> 2] |= 128 << (i % 4 << 3);
178
+ if (i > 55) {
179
+ md5cycle(state, tail);
180
+ for (i = 0; i < 16; i += 1) {
181
+ tail[i] = 0;
182
+ }
183
+ }
184
+ tmp = n * 8;
185
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
186
+ lo = parseInt(tmp[2], 16);
187
+ hi = parseInt(tmp[1], 16) || 0;
188
+ tail[14] = lo;
189
+ tail[15] = hi;
190
+ md5cycle(state, tail);
191
+ return state;
192
+ }
193
+ function md51_array(a) {
194
+ var n = a.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;
195
+ for (i = 64; i <= n; i += 64) {
196
+ md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
197
+ }
198
+ a = i - 64 < n ? a.subarray(i - 64) : new Uint8Array(0);
199
+ length = a.length;
200
+ tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
201
+ for (i = 0; i < length; i += 1) {
202
+ tail[i >> 2] |= a[i] << (i % 4 << 3);
203
+ }
204
+ tail[i >> 2] |= 128 << (i % 4 << 3);
205
+ if (i > 55) {
206
+ md5cycle(state, tail);
207
+ for (i = 0; i < 16; i += 1) {
208
+ tail[i] = 0;
209
+ }
210
+ }
211
+ tmp = n * 8;
212
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
213
+ lo = parseInt(tmp[2], 16);
214
+ hi = parseInt(tmp[1], 16) || 0;
215
+ tail[14] = lo;
216
+ tail[15] = hi;
217
+ md5cycle(state, tail);
218
+ return state;
219
+ }
220
+ function rhex(n) {
221
+ var s = "", j;
222
+ for (j = 0; j < 4; j += 1) {
223
+ s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];
224
+ }
225
+ return s;
226
+ }
227
+ function hex(x) {
228
+ var i;
229
+ for (i = 0; i < x.length; i += 1) {
230
+ x[i] = rhex(x[i]);
231
+ }
232
+ return x.join("");
233
+ }
234
+ if (hex(md51("hello")) !== "5d41402abc4b2a76b9719d911017c592") ;
235
+ if (typeof ArrayBuffer !== "undefined" && !ArrayBuffer.prototype.slice) {
236
+ (function() {
237
+ function clamp(val, length) {
238
+ val = val | 0 || 0;
239
+ if (val < 0) {
240
+ return Math.max(val + length, 0);
241
+ }
242
+ return Math.min(val, length);
243
+ }
244
+ ArrayBuffer.prototype.slice = function(from, to) {
245
+ var length = this.byteLength, begin = clamp(from, length), end = length, num, target, targetArray, sourceArray;
246
+ if (to !== undefined) {
247
+ end = clamp(to, length);
248
+ }
249
+ if (begin > end) {
250
+ return new ArrayBuffer(0);
251
+ }
252
+ num = end - begin;
253
+ target = new ArrayBuffer(num);
254
+ targetArray = new Uint8Array(target);
255
+ sourceArray = new Uint8Array(this, begin, num);
256
+ targetArray.set(sourceArray);
257
+ return target;
258
+ };
259
+ })();
260
+ }
261
+ function toUtf8(str) {
262
+ if (/[\u0080-\uFFFF]/.test(str)) {
263
+ str = unescape(encodeURIComponent(str));
264
+ }
265
+ return str;
266
+ }
267
+ function utf8Str2ArrayBuffer(str, returnUInt8Array) {
268
+ var length = str.length, buff = new ArrayBuffer(length), arr = new Uint8Array(buff), i;
269
+ for (i = 0; i < length; i += 1) {
270
+ arr[i] = str.charCodeAt(i);
271
+ }
272
+ return returnUInt8Array ? arr : buff;
273
+ }
274
+ function arrayBuffer2Utf8Str(buff) {
275
+ return String.fromCharCode.apply(null, new Uint8Array(buff));
276
+ }
277
+ function concatenateArrayBuffers(first, second, returnUInt8Array) {
278
+ var result = new Uint8Array(first.byteLength + second.byteLength);
279
+ result.set(new Uint8Array(first));
280
+ result.set(new Uint8Array(second), first.byteLength);
281
+ return returnUInt8Array ? result : result.buffer;
282
+ }
283
+ function hexToBinaryString(hex) {
284
+ var bytes = [], length = hex.length, x;
285
+ for (x = 0; x < length - 1; x += 2) {
286
+ bytes.push(parseInt(hex.substr(x, 2), 16));
287
+ }
288
+ return String.fromCharCode.apply(String, bytes);
289
+ }
290
+ function SparkMD5() {
291
+ this.reset();
292
+ }
293
+ SparkMD5.prototype.append = function(str) {
294
+ this.appendBinary(toUtf8(str));
295
+ return this;
296
+ };
297
+ SparkMD5.prototype.appendBinary = function(contents) {
298
+ this._buff += contents;
299
+ this._length += contents.length;
300
+ var length = this._buff.length, i;
301
+ for (i = 64; i <= length; i += 64) {
302
+ md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
303
+ }
304
+ this._buff = this._buff.substring(i - 64);
305
+ return this;
306
+ };
307
+ SparkMD5.prototype.end = function(raw) {
308
+ var buff = this._buff, length = buff.length, i, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], ret;
309
+ for (i = 0; i < length; i += 1) {
310
+ tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);
311
+ }
312
+ this._finish(tail, length);
313
+ ret = hex(this._hash);
314
+ if (raw) {
315
+ ret = hexToBinaryString(ret);
316
+ }
317
+ this.reset();
318
+ return ret;
319
+ };
320
+ SparkMD5.prototype.reset = function() {
321
+ this._buff = "";
322
+ this._length = 0;
323
+ this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];
324
+ return this;
325
+ };
326
+ SparkMD5.prototype.getState = function() {
327
+ return {
328
+ buff: this._buff,
329
+ length: this._length,
330
+ hash: this._hash
331
+ };
332
+ };
333
+ SparkMD5.prototype.setState = function(state) {
334
+ this._buff = state.buff;
335
+ this._length = state.length;
336
+ this._hash = state.hash;
337
+ return this;
338
+ };
339
+ SparkMD5.prototype.destroy = function() {
340
+ delete this._hash;
341
+ delete this._buff;
342
+ delete this._length;
343
+ };
344
+ SparkMD5.prototype._finish = function(tail, length) {
345
+ var i = length, tmp, lo, hi;
346
+ tail[i >> 2] |= 128 << (i % 4 << 3);
347
+ if (i > 55) {
348
+ md5cycle(this._hash, tail);
349
+ for (i = 0; i < 16; i += 1) {
350
+ tail[i] = 0;
351
+ }
352
+ }
353
+ tmp = this._length * 8;
354
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
355
+ lo = parseInt(tmp[2], 16);
356
+ hi = parseInt(tmp[1], 16) || 0;
357
+ tail[14] = lo;
358
+ tail[15] = hi;
359
+ md5cycle(this._hash, tail);
360
+ };
361
+ SparkMD5.hash = function(str, raw) {
362
+ return SparkMD5.hashBinary(toUtf8(str), raw);
363
+ };
364
+ SparkMD5.hashBinary = function(content, raw) {
365
+ var hash = md51(content), ret = hex(hash);
366
+ return raw ? hexToBinaryString(ret) : ret;
367
+ };
368
+ SparkMD5.ArrayBuffer = function() {
369
+ this.reset();
370
+ };
371
+ SparkMD5.ArrayBuffer.prototype.append = function(arr) {
372
+ var buff = concatenateArrayBuffers(this._buff.buffer, arr, true), length = buff.length, i;
373
+ this._length += arr.byteLength;
374
+ for (i = 64; i <= length; i += 64) {
375
+ md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
376
+ }
377
+ this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);
378
+ return this;
379
+ };
380
+ SparkMD5.ArrayBuffer.prototype.end = function(raw) {
381
+ var buff = this._buff, length = buff.length, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], i, ret;
382
+ for (i = 0; i < length; i += 1) {
383
+ tail[i >> 2] |= buff[i] << (i % 4 << 3);
384
+ }
385
+ this._finish(tail, length);
386
+ ret = hex(this._hash);
387
+ if (raw) {
388
+ ret = hexToBinaryString(ret);
389
+ }
390
+ this.reset();
391
+ return ret;
392
+ };
393
+ SparkMD5.ArrayBuffer.prototype.reset = function() {
394
+ this._buff = new Uint8Array(0);
395
+ this._length = 0;
396
+ this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];
397
+ return this;
398
+ };
399
+ SparkMD5.ArrayBuffer.prototype.getState = function() {
400
+ var state = SparkMD5.prototype.getState.call(this);
401
+ state.buff = arrayBuffer2Utf8Str(state.buff);
402
+ return state;
403
+ };
404
+ SparkMD5.ArrayBuffer.prototype.setState = function(state) {
405
+ state.buff = utf8Str2ArrayBuffer(state.buff, true);
406
+ return SparkMD5.prototype.setState.call(this, state);
407
+ };
408
+ SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
409
+ SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
410
+ SparkMD5.ArrayBuffer.hash = function(arr, raw) {
411
+ var hash = md51_array(new Uint8Array(arr)), ret = hex(hash);
412
+ return raw ? hexToBinaryString(ret) : ret;
413
+ };
414
+ return SparkMD5;
415
+ });
416
+ });
417
+ var classCallCheck = function(instance, Constructor) {
418
+ if (!(instance instanceof Constructor)) {
419
+ throw new TypeError("Cannot call a class as a function");
420
+ }
421
+ };
422
+ var createClass = function() {
423
+ function defineProperties(target, props) {
424
+ for (var i = 0; i < props.length; i++) {
425
+ var descriptor = props[i];
426
+ descriptor.enumerable = descriptor.enumerable || false;
427
+ descriptor.configurable = true;
428
+ if ("value" in descriptor) descriptor.writable = true;
429
+ Object.defineProperty(target, descriptor.key, descriptor);
430
+ }
431
+ }
432
+ return function(Constructor, protoProps, staticProps) {
433
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
434
+ if (staticProps) defineProperties(Constructor, staticProps);
435
+ return Constructor;
436
+ };
437
+ }();
438
+ var fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
439
+ var FileChecksum = function() {
440
+ createClass(FileChecksum, null, [ {
441
+ key: "create",
442
+ value: function create(file, callback) {
443
+ var instance = new FileChecksum(file);
444
+ instance.create(callback);
445
+ }
446
+ } ]);
447
+ function FileChecksum(file) {
448
+ classCallCheck(this, FileChecksum);
449
+ this.file = file;
450
+ this.chunkSize = 2097152;
451
+ this.chunkCount = Math.ceil(this.file.size / this.chunkSize);
452
+ this.chunkIndex = 0;
453
+ }
454
+ createClass(FileChecksum, [ {
455
+ key: "create",
456
+ value: function create(callback) {
457
+ var _this = this;
458
+ this.callback = callback;
459
+ this.md5Buffer = new sparkMd5.ArrayBuffer();
460
+ this.fileReader = new FileReader();
461
+ this.fileReader.addEventListener("load", function(event) {
462
+ return _this.fileReaderDidLoad(event);
463
+ });
464
+ this.fileReader.addEventListener("error", function(event) {
465
+ return _this.fileReaderDidError(event);
466
+ });
467
+ this.readNextChunk();
468
+ }
469
+ }, {
470
+ key: "fileReaderDidLoad",
471
+ value: function fileReaderDidLoad(event) {
472
+ this.md5Buffer.append(event.target.result);
473
+ if (!this.readNextChunk()) {
474
+ var binaryDigest = this.md5Buffer.end(true);
475
+ var base64digest = btoa(binaryDigest);
476
+ this.callback(null, base64digest);
477
+ }
478
+ }
479
+ }, {
480
+ key: "fileReaderDidError",
481
+ value: function fileReaderDidError(event) {
482
+ this.callback("Error reading " + this.file.name);
483
+ }
484
+ }, {
485
+ key: "readNextChunk",
486
+ value: function readNextChunk() {
487
+ if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {
488
+ var start = this.chunkIndex * this.chunkSize;
489
+ var end = Math.min(start + this.chunkSize, this.file.size);
490
+ var bytes = fileSlice.call(this.file, start, end);
491
+ this.fileReader.readAsArrayBuffer(bytes);
492
+ this.chunkIndex++;
493
+ return true;
494
+ } else {
495
+ return false;
496
+ }
497
+ }
498
+ } ]);
499
+ return FileChecksum;
500
+ }();
501
+ function getMetaValue(name) {
502
+ var element = findElement(document.head, 'meta[name="' + name + '"]');
503
+ if (element) {
504
+ return element.getAttribute("content");
505
+ }
506
+ }
507
+ function findElements(root, selector) {
508
+ if (typeof root == "string") {
509
+ selector = root;
510
+ root = document;
511
+ }
512
+ var elements = root.querySelectorAll(selector);
513
+ return toArray$1(elements);
514
+ }
515
+ function findElement(root, selector) {
516
+ if (typeof root == "string") {
517
+ selector = root;
518
+ root = document;
519
+ }
520
+ return root.querySelector(selector);
521
+ }
522
+ function dispatchEvent(element, type) {
523
+ var eventInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
524
+ var disabled = element.disabled;
525
+ var bubbles = eventInit.bubbles, cancelable = eventInit.cancelable, detail = eventInit.detail;
526
+ var event = document.createEvent("Event");
527
+ event.initEvent(type, bubbles || true, cancelable || true);
528
+ event.detail = detail || {};
529
+ try {
530
+ element.disabled = false;
531
+ element.dispatchEvent(event);
532
+ } finally {
533
+ element.disabled = disabled;
534
+ }
535
+ return event;
536
+ }
537
+ function toArray$1(value) {
538
+ if (Array.isArray(value)) {
539
+ return value;
540
+ } else if (Array.from) {
541
+ return Array.from(value);
542
+ } else {
543
+ return [].slice.call(value);
544
+ }
545
+ }
546
+ var BlobRecord = function() {
547
+ function BlobRecord(file, checksum, url) {
548
+ var _this = this;
549
+ classCallCheck(this, BlobRecord);
550
+ this.file = file;
551
+ this.attributes = {
552
+ filename: file.name,
553
+ content_type: file.type,
554
+ byte_size: file.size,
555
+ checksum: checksum
556
+ };
557
+ this.xhr = new XMLHttpRequest();
558
+ this.xhr.open("POST", url, true);
559
+ this.xhr.responseType = "json";
560
+ this.xhr.setRequestHeader("Content-Type", "application/json");
561
+ this.xhr.setRequestHeader("Accept", "application/json");
562
+ this.xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
563
+ this.xhr.setRequestHeader("X-CSRF-Token", getMetaValue("csrf-token"));
564
+ this.xhr.addEventListener("load", function(event) {
565
+ return _this.requestDidLoad(event);
566
+ });
567
+ this.xhr.addEventListener("error", function(event) {
568
+ return _this.requestDidError(event);
569
+ });
570
+ }
571
+ createClass(BlobRecord, [ {
572
+ key: "create",
573
+ value: function create(callback) {
574
+ this.callback = callback;
575
+ this.xhr.send(JSON.stringify({
576
+ blob: this.attributes
577
+ }));
578
+ }
579
+ }, {
580
+ key: "requestDidLoad",
581
+ value: function requestDidLoad(event) {
582
+ if (this.status >= 200 && this.status < 300) {
583
+ var response = this.response;
584
+ var direct_upload = response.direct_upload;
585
+ delete response.direct_upload;
586
+ this.attributes = response;
587
+ this.directUploadData = direct_upload;
588
+ this.callback(null, this.toJSON());
589
+ } else {
590
+ this.requestDidError(event);
591
+ }
592
+ }
593
+ }, {
594
+ key: "requestDidError",
595
+ value: function requestDidError(event) {
596
+ this.callback('Error creating Blob for "' + this.file.name + '". Status: ' + this.status);
597
+ }
598
+ }, {
599
+ key: "toJSON",
600
+ value: function toJSON() {
601
+ var result = {};
602
+ for (var key in this.attributes) {
603
+ result[key] = this.attributes[key];
604
+ }
605
+ return result;
606
+ }
607
+ }, {
608
+ key: "status",
609
+ get: function get$$1() {
610
+ return this.xhr.status;
611
+ }
612
+ }, {
613
+ key: "response",
614
+ get: function get$$1() {
615
+ var _xhr = this.xhr, responseType = _xhr.responseType, response = _xhr.response;
616
+ if (responseType == "json") {
617
+ return response;
618
+ } else {
619
+ return JSON.parse(response);
620
+ }
621
+ }
622
+ } ]);
623
+ return BlobRecord;
624
+ }();
625
+ var BlobUpload = function() {
626
+ function BlobUpload(blob) {
627
+ var _this = this;
628
+ classCallCheck(this, BlobUpload);
629
+ this.blob = blob;
630
+ this.file = blob.file;
631
+ var _blob$directUploadDat = blob.directUploadData, url = _blob$directUploadDat.url, headers = _blob$directUploadDat.headers;
632
+ this.xhr = new XMLHttpRequest();
633
+ this.xhr.open("PUT", url, true);
634
+ this.xhr.responseType = "text";
635
+ for (var key in headers) {
636
+ this.xhr.setRequestHeader(key, headers[key]);
637
+ }
638
+ this.xhr.addEventListener("load", function(event) {
639
+ return _this.requestDidLoad(event);
640
+ });
641
+ this.xhr.addEventListener("error", function(event) {
642
+ return _this.requestDidError(event);
643
+ });
644
+ }
645
+ createClass(BlobUpload, [ {
646
+ key: "create",
647
+ value: function create(callback) {
648
+ this.callback = callback;
649
+ this.xhr.send(this.file.slice());
650
+ }
651
+ }, {
652
+ key: "requestDidLoad",
653
+ value: function requestDidLoad(event) {
654
+ var _xhr = this.xhr, status = _xhr.status, response = _xhr.response;
655
+ if (status >= 200 && status < 300) {
656
+ this.callback(null, response);
657
+ } else {
658
+ this.requestDidError(event);
659
+ }
660
+ }
661
+ }, {
662
+ key: "requestDidError",
663
+ value: function requestDidError(event) {
664
+ this.callback('Error storing "' + this.file.name + '". Status: ' + this.xhr.status);
665
+ }
666
+ } ]);
667
+ return BlobUpload;
668
+ }();
669
+ var id = 0;
670
+ var DirectUpload = function() {
671
+ function DirectUpload(file, url, delegate) {
672
+ classCallCheck(this, DirectUpload);
673
+ this.id = ++id;
674
+ this.file = file;
675
+ this.url = url;
676
+ this.delegate = delegate;
677
+ }
678
+ createClass(DirectUpload, [ {
679
+ key: "create",
680
+ value: function create(callback) {
681
+ var _this = this;
682
+ FileChecksum.create(this.file, function(error, checksum) {
683
+ if (error) {
684
+ callback(error);
685
+ return;
686
+ }
687
+ var blob = new BlobRecord(_this.file, checksum, _this.url);
688
+ notify(_this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr);
689
+ blob.create(function(error) {
690
+ if (error) {
691
+ callback(error);
692
+ } else {
693
+ var upload = new BlobUpload(blob);
694
+ notify(_this.delegate, "directUploadWillStoreFileWithXHR", upload.xhr);
695
+ upload.create(function(error) {
696
+ if (error) {
697
+ callback(error);
698
+ } else {
699
+ callback(null, blob.toJSON());
700
+ }
701
+ });
702
+ }
703
+ });
704
+ });
705
+ }
706
+ } ]);
707
+ return DirectUpload;
708
+ }();
709
+ function notify(object, methodName) {
710
+ if (object && typeof object[methodName] == "function") {
711
+ for (var _len = arguments.length, messages = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
712
+ messages[_key - 2] = arguments[_key];
713
+ }
714
+ return object[methodName].apply(object, messages);
715
+ }
716
+ }
717
+ var DirectUploadController = function() {
718
+ function DirectUploadController(input, file) {
719
+ classCallCheck(this, DirectUploadController);
720
+ this.input = input;
721
+ this.file = file;
722
+ this.directUpload = new DirectUpload(this.file, this.url, this);
723
+ this.dispatch("initialize");
724
+ }
725
+ createClass(DirectUploadController, [ {
726
+ key: "start",
727
+ value: function start(callback) {
728
+ var _this = this;
729
+ var hiddenInput = document.createElement("input");
730
+ hiddenInput.type = "hidden";
731
+ hiddenInput.name = this.input.name;
732
+ this.input.insertAdjacentElement("beforebegin", hiddenInput);
733
+ this.dispatch("start");
734
+ this.directUpload.create(function(error, attributes) {
735
+ if (error) {
736
+ hiddenInput.parentNode.removeChild(hiddenInput);
737
+ _this.dispatchError(error);
738
+ } else {
739
+ hiddenInput.value = attributes.signed_id;
740
+ }
741
+ _this.dispatch("end");
742
+ callback(error);
743
+ });
744
+ }
745
+ }, {
746
+ key: "uploadRequestDidProgress",
747
+ value: function uploadRequestDidProgress(event) {
748
+ var progress = event.loaded / event.total * 100;
749
+ if (progress) {
750
+ this.dispatch("progress", {
751
+ progress: progress
752
+ });
753
+ }
754
+ }
755
+ }, {
756
+ key: "dispatch",
757
+ value: function dispatch(name) {
758
+ var detail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
759
+ detail.file = this.file;
760
+ detail.id = this.directUpload.id;
761
+ return dispatchEvent(this.input, "direct-upload:" + name, {
762
+ detail: detail
763
+ });
764
+ }
765
+ }, {
766
+ key: "dispatchError",
767
+ value: function dispatchError(error) {
768
+ var event = this.dispatch("error", {
769
+ error: error
770
+ });
771
+ if (!event.defaultPrevented) {
772
+ alert(error);
773
+ }
774
+ }
775
+ }, {
776
+ key: "directUploadWillCreateBlobWithXHR",
777
+ value: function directUploadWillCreateBlobWithXHR(xhr) {
778
+ this.dispatch("before-blob-request", {
779
+ xhr: xhr
780
+ });
781
+ }
782
+ }, {
783
+ key: "directUploadWillStoreFileWithXHR",
784
+ value: function directUploadWillStoreFileWithXHR(xhr) {
785
+ var _this2 = this;
786
+ this.dispatch("before-storage-request", {
787
+ xhr: xhr
788
+ });
789
+ xhr.upload.addEventListener("progress", function(event) {
790
+ return _this2.uploadRequestDidProgress(event);
791
+ });
792
+ }
793
+ }, {
794
+ key: "url",
795
+ get: function get$$1() {
796
+ return this.input.getAttribute("data-direct-upload-url");
797
+ }
798
+ } ]);
799
+ return DirectUploadController;
800
+ }();
801
+ var inputSelector = "input[type=file][data-direct-upload-url]:not([disabled])";
802
+ var DirectUploadsController = function() {
803
+ function DirectUploadsController(form) {
804
+ classCallCheck(this, DirectUploadsController);
805
+ this.form = form;
806
+ this.inputs = findElements(form, inputSelector).filter(function(input) {
807
+ return input.files.length;
808
+ });
809
+ }
810
+ createClass(DirectUploadsController, [ {
811
+ key: "start",
812
+ value: function start(callback) {
813
+ var _this = this;
814
+ var controllers = this.createDirectUploadControllers();
815
+ var startNextController = function startNextController() {
816
+ var controller = controllers.shift();
817
+ if (controller) {
818
+ controller.start(function(error) {
819
+ if (error) {
820
+ callback(error);
821
+ _this.dispatch("end");
822
+ } else {
823
+ startNextController();
824
+ }
825
+ });
826
+ } else {
827
+ callback();
828
+ _this.dispatch("end");
829
+ }
830
+ };
831
+ this.dispatch("start");
832
+ startNextController();
833
+ }
834
+ }, {
835
+ key: "createDirectUploadControllers",
836
+ value: function createDirectUploadControllers() {
837
+ var controllers = [];
838
+ this.inputs.forEach(function(input) {
839
+ toArray$1(input.files).forEach(function(file) {
840
+ var controller = new DirectUploadController(input, file);
841
+ controllers.push(controller);
842
+ });
843
+ });
844
+ return controllers;
845
+ }
846
+ }, {
847
+ key: "dispatch",
848
+ value: function dispatch(name) {
849
+ var detail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
850
+ return dispatchEvent(this.form, "direct-uploads:" + name, {
851
+ detail: detail
852
+ });
853
+ }
854
+ } ]);
855
+ return DirectUploadsController;
856
+ }();
857
+ var processingAttribute = "data-direct-uploads-processing";
858
+ var submitButtonsByForm = new WeakMap();
859
+ var started = false;
860
+ function start() {
861
+ if (!started) {
862
+ started = true;
863
+ document.addEventListener("click", didClick, true);
864
+ document.addEventListener("submit", didSubmitForm);
865
+ document.addEventListener("ajax:before", didSubmitRemoteElement);
866
+ }
867
+ }
868
+ function didClick(event) {
869
+ var target = event.target;
870
+ if ((target.tagName == "INPUT" || target.tagName == "BUTTON") && target.type == "submit" && target.form) {
871
+ submitButtonsByForm.set(target.form, target);
872
+ }
873
+ }
874
+ function didSubmitForm(event) {
875
+ handleFormSubmissionEvent(event);
876
+ }
877
+ function didSubmitRemoteElement(event) {
878
+ if (event.target.tagName == "FORM") {
879
+ handleFormSubmissionEvent(event);
880
+ }
881
+ }
882
+ function handleFormSubmissionEvent(event) {
883
+ var form = event.target;
884
+ if (form.hasAttribute(processingAttribute)) {
885
+ event.preventDefault();
886
+ return;
887
+ }
888
+ var controller = new DirectUploadsController(form);
889
+ var inputs = controller.inputs;
890
+ if (inputs.length) {
891
+ event.preventDefault();
892
+ form.setAttribute(processingAttribute, "");
893
+ inputs.forEach(disable);
894
+ controller.start(function(error) {
895
+ form.removeAttribute(processingAttribute);
896
+ if (error) {
897
+ inputs.forEach(enable);
898
+ } else {
899
+ submitForm(form);
900
+ }
901
+ });
902
+ }
903
+ }
904
+ function submitForm(form) {
905
+ var button = submitButtonsByForm.get(form) || findElement(form, "input[type=submit], button[type=submit]");
906
+ if (button) {
907
+ var _button = button, disabled = _button.disabled;
908
+ button.disabled = false;
909
+ button.focus();
910
+ button.click();
911
+ button.disabled = disabled;
912
+ } else {
913
+ button = document.createElement("input");
914
+ button.type = "submit";
915
+ button.style.display = "none";
916
+ form.appendChild(button);
917
+ button.click();
918
+ form.removeChild(button);
919
+ }
920
+ submitButtonsByForm.delete(form);
921
+ }
922
+ function disable(input) {
923
+ input.disabled = true;
924
+ }
925
+ function enable(input) {
926
+ input.disabled = false;
927
+ }
928
+ function autostart() {
929
+ if (window.ActiveStorage) {
930
+ start();
931
+ }
932
+ }
933
+ setTimeout(autostart, 1);
934
+ exports.start = start;
935
+ exports.DirectUpload = DirectUpload;
936
+ Object.defineProperty(exports, "__esModule", {
937
+ value: true
938
+ });
939
+ });