activestorage 5.2.1.1 → 5.2.2.rc1

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: 91213c28f24de81bd5f9fb70fc824cebab2a78b4a9a7e7181dab0073241e10df
4
- data.tar.gz: be7321827bdee9da52fb288c8625c1d06c13efcea0e7e38115294cc7c87f1629
3
+ metadata.gz: b4189d77369b86d75ccd00eb8cb4041f6fb8ef9380260ca6406cd1fe52ab8d64
4
+ data.tar.gz: efa6e485ff239324cb18efe838f65af94052423d113801cb5c98fe431a030ab8
5
5
  SHA512:
6
- metadata.gz: 020ebe643211ff9093027c6ec35a0626e565779a0f0d9a27723cb452b1c66cf9c1b10df89aec84cf068ef1d24ddb90ef8b844054eaaa497bc41b59e42a0f0514
7
- data.tar.gz: 9c3e51fbe837f60c86eb993d9ba1d85b66362a298fb432629f1dca0b79bdbd500c86fb6640d99d023636d4f8094867367b7cb2bd5d2b6616fe93fa9a8dea6a13
6
+ metadata.gz: 30da7beb82a8ca062edec0c7b4f10988332a63b4c2c5b64df88a95d34b42e75159e615a4ffaae21c30f6cb4dd3d6afd9ddfd731122bc86d1a5b1730889fb9d9f
7
+ data.tar.gz: ce7d54fb040dd0fcbe2ec5fe770bbfd5d7497b10f43fc294086ee506faa336bd1fe110069930fd96eab32ccd7fbb52ba0368eceb58013a4a94ab83bf0f8f0f4c
@@ -1,3 +1,26 @@
1
+ ## Rails 5.2.2.rc1 (November 28, 2018) ##
2
+
3
+ * Support multiple submit buttons in Active Storage forms.
4
+
5
+ *Chrıs Seelus*
6
+
7
+ * Fix `ArgumentError` when uploading to amazon s3
8
+
9
+ *Hiroki Sanpei*
10
+
11
+ * Add a foreign-key constraint to the `active_storage_attachments` table for blobs.
12
+
13
+ *George Claghorn*
14
+
15
+ * Discard `ActiveStorage::PurgeJobs` for missing blobs.
16
+
17
+ *George Claghorn*
18
+
19
+ * Fix uploading Tempfiles to Azure Storage.
20
+
21
+ *George Claghorn*
22
+
23
+
1
24
  ## Rails 5.2.1.1 (November 27, 2018) ##
2
25
 
3
26
  * Prevent content type and disposition bypass in storage service URLs.
@@ -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
+ });
@@ -5,23 +5,14 @@
5
5
  # Always go through the BlobsController, or your own authenticated controller, rather than directly
6
6
  # to the service url.
7
7
  class ActiveStorage::DiskController < ActiveStorage::BaseController
8
- include ActionController::Live
9
-
10
8
  skip_forgery_protection
11
9
 
12
10
  def show
13
11
  if key = decode_verified_key
14
- response.headers["Content-Type"] = key[:content_type] || DEFAULT_SEND_FILE_TYPE
15
- response.headers["Content-Disposition"] = key[:disposition] || DEFAULT_SEND_FILE_DISPOSITION
16
-
17
- disk_service.download key[:key] do |chunk|
18
- response.stream.write chunk
19
- end
12
+ serve_file disk_service.path_for(key[:key]), content_type: key[:content_type], disposition: key[:disposition]
20
13
  else
21
14
  head :not_found
22
15
  end
23
- ensure
24
- response.stream.close
25
16
  end
26
17
 
27
18
  def update
@@ -32,13 +23,9 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
32
23
  else
33
24
  head :unprocessable_entity
34
25
  end
35
- else
36
- head :not_found
37
26
  end
38
27
  rescue ActiveStorage::IntegrityError
39
28
  head :unprocessable_entity
40
- ensure
41
- response.stream.close
42
29
  end
43
30
 
44
31
  private
@@ -51,12 +38,26 @@ class ActiveStorage::DiskController < ActiveStorage::BaseController
51
38
  ActiveStorage.verifier.verified(params[:encoded_key], purpose: :blob_key)
52
39
  end
53
40
 
41
+ def serve_file(path, content_type:, disposition:)
42
+ Rack::File.new(nil).serving(request, path).tap do |(status, headers, body)|
43
+ self.status = status
44
+ self.response_body = body
45
+
46
+ headers.each do |name, value|
47
+ response.headers[name] = value
48
+ end
49
+
50
+ response.headers["Content-Type"] = content_type || DEFAULT_SEND_FILE_TYPE
51
+ response.headers["Content-Disposition"] = disposition || DEFAULT_SEND_FILE_DISPOSITION
52
+ end
53
+ end
54
+
54
55
 
55
56
  def decode_verified_token
56
57
  ActiveStorage.verifier.verified(params[:encoded_token], purpose: :blob_token)
57
58
  end
58
59
 
59
60
  def acceptable_content?(token)
60
- token[:content_type] == request.content_type && token[:content_length] == request.content_length
61
+ token[:content_type] == request.content_mime_type && token[:content_length] == request.content_length
61
62
  end
62
63
  end
@@ -2,16 +2,25 @@ import { DirectUploadsController } from "./direct_uploads_controller"
2
2
  import { findElement } from "./helpers"
3
3
 
4
4
  const processingAttribute = "data-direct-uploads-processing"
5
+ const submitButtonsByForm = new WeakMap
5
6
  let started = false
6
7
 
7
8
  export function start() {
8
9
  if (!started) {
9
10
  started = true
11
+ document.addEventListener("click", didClick, true)
10
12
  document.addEventListener("submit", didSubmitForm)
11
13
  document.addEventListener("ajax:before", didSubmitRemoteElement)
12
14
  }
13
15
  }
14
16
 
17
+ function didClick(event) {
18
+ const { target } = event
19
+ if ((target.tagName == "INPUT" || target.tagName == "BUTTON") && target.type == "submit" && target.form) {
20
+ submitButtonsByForm.set(target.form, target)
21
+ }
22
+ }
23
+
15
24
  function didSubmitForm(event) {
16
25
  handleFormSubmissionEvent(event)
17
26
  }
@@ -49,7 +58,8 @@ function handleFormSubmissionEvent(event) {
49
58
  }
50
59
 
51
60
  function submitForm(form) {
52
- let button = findElement(form, "input[type=submit]")
61
+ let button = submitButtonsByForm.get(form) || findElement(form, "input[type=submit], button[type=submit]")
62
+
53
63
  if (button) {
54
64
  const { disabled } = button
55
65
  button.disabled = false
@@ -64,6 +74,7 @@ function submitForm(form) {
64
74
  button.click()
65
75
  form.removeChild(button)
66
76
  }
77
+ submitButtonsByForm.delete(form)
67
78
  }
68
79
 
69
80
  function disable(input) {
@@ -2,8 +2,7 @@
2
2
 
3
3
  # Provides asynchronous purging of ActiveStorage::Blob records via ActiveStorage::Blob#purge_later.
4
4
  class ActiveStorage::PurgeJob < ActiveStorage::BaseJob
5
- # FIXME: Limit this to a custom ActiveStorage error
6
- retry_on StandardError
5
+ discard_on ActiveRecord::RecordNotFound
7
6
 
8
7
  def perform(blob)
9
8
  blob.purge
@@ -18,14 +18,14 @@ class ActiveStorage::Attachment < ActiveRecord::Base
18
18
 
19
19
  # Synchronously purges the blob (deletes it from the configured service) and destroys the attachment.
20
20
  def purge
21
- blob.purge
22
21
  destroy
22
+ blob.purge
23
23
  end
24
24
 
25
25
  # Destroys the attachment and asynchronously purges the blob (deletes it from the configured service).
26
26
  def purge_later
27
- blob.purge_later
28
27
  destroy
28
+ blob.purge_later
29
29
  end
30
30
 
31
31
  private
@@ -33,6 +33,10 @@ class ActiveStorage::Blob < ActiveRecord::Base
33
33
 
34
34
  scope :unattached, -> { left_joins(:attachments).where(ActiveStorage::Attachment.table_name => { blob_id: nil }) }
35
35
 
36
+ before_destroy(prepend: true) do
37
+ raise ActiveRecord::InvalidForeignKey if attachments.exists?
38
+ end
39
+
36
40
  class << self
37
41
  # You can used the signed ID of a blob to refer to it on the client side without fear of tampering.
38
42
  # This is particularly helpful for direct uploads where the client-side needs to refer to the blob
@@ -174,8 +178,9 @@ class ActiveStorage::Blob < ActiveRecord::Base
174
178
  # blobs. Note, though, that deleting the file off the service will initiate a HTTP connection to the service, which may
175
179
  # be slow or prevented, so you should not use this method inside a transaction or in callbacks. Use +#purge_later+ instead.
176
180
  def purge
177
- delete
178
181
  destroy
182
+ delete
183
+ rescue ActiveRecord::InvalidForeignKey
179
184
  end
180
185
 
181
186
  # Enqueues an ActiveStorage::PurgeJob job that'll call +purge+. This is the recommended way to purge blobs when the call
@@ -18,7 +18,11 @@ module ActiveStorage::Blob::Identifiable
18
18
  end
19
19
 
20
20
  def download_identifiable_chunk
21
- service.download_chunk key, 0...4.kilobytes
21
+ if byte_size.positive?
22
+ service.download_chunk key, 0...4.kilobytes
23
+ else
24
+ ""
25
+ end
22
26
  end
23
27
 
24
28
  def update_service_metadata
@@ -20,6 +20,7 @@ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
20
20
  t.datetime :created_at, null: false
21
21
 
22
22
  t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
23
+ t.foreign_key :active_storage_blobs, column: :blob_id
23
24
  end
24
25
  end
25
26
  end
@@ -9,8 +9,8 @@ module ActiveStorage
9
9
  module VERSION
10
10
  MAJOR = 5
11
11
  MINOR = 2
12
- TINY = 1
13
- PRE = "1"
12
+ TINY = 2
13
+ PRE = "rc1"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -123,11 +123,11 @@ module ActiveStorage
123
123
  { "Content-Type" => content_type }
124
124
  end
125
125
 
126
- private
127
- def path_for(key)
128
- File.join root, folder_for(key), key
129
- end
126
+ def path_for(key) #:nodoc:
127
+ File.join root, folder_for(key), key
128
+ end
130
129
 
130
+ private
131
131
  def folder_for(key)
132
132
  [ key[0..1], key[2..3] ].join("/")
133
133
  end
@@ -16,7 +16,7 @@ module ActiveStorage
16
16
  @upload_options = upload
17
17
  end
18
18
 
19
- def upload(key, io, checksum: nil)
19
+ def upload(key, io, checksum: nil, **)
20
20
  instrument :upload, key: key, checksum: checksum do
21
21
  begin
22
22
  object_for(key).put(upload_options.merge(body: io, content_md5: checksum))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1.1
4
+ version: 5.2.2.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-27 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.1.1
19
+ version: 5.2.2.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.1.1
26
+ version: 5.2.2.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 5.2.1.1
33
+ version: 5.2.2.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 5.2.1.1
40
+ version: 5.2.2.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: marcel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -124,8 +124,8 @@ homepage: http://rubyonrails.org
124
124
  licenses:
125
125
  - MIT
126
126
  metadata:
127
- source_code_uri: https://github.com/rails/rails/tree/v5.2.1.1/activestorage
128
- changelog_uri: https://github.com/rails/rails/blob/v5.2.1.1/activestorage/CHANGELOG.md
127
+ source_code_uri: https://github.com/rails/rails/tree/v5.2.2.rc1/activestorage
128
+ changelog_uri: https://github.com/rails/rails/blob/v5.2.2.rc1/activestorage/CHANGELOG.md
129
129
  post_install_message:
130
130
  rdoc_options: []
131
131
  require_paths:
@@ -137,9 +137,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  version: 2.2.2
138
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - ">="
140
+ - - ">"
141
141
  - !ruby/object:Gem::Version
142
- version: '0'
142
+ version: 1.3.1
143
143
  requirements: []
144
144
  rubyforge_project:
145
145
  rubygems_version: 2.7.6