tessa 0.9.2 → 1.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/.babelrc +8 -0
  3. data/.circleci/config.yml +42 -0
  4. data/.eslintrc +19 -0
  5. data/.gitignore +5 -0
  6. data/.ruby-version +1 -1
  7. data/Rakefile +8 -0
  8. data/app/assets/javascripts/.keep +0 -0
  9. data/app/assets/javascripts/tessa.esm.js +672 -0
  10. data/app/assets/javascripts/tessa.js +662 -0
  11. data/app/javascript/activestorage/file_checksum.js +53 -0
  12. data/app/javascript/tessa/index.js.coffee +183 -0
  13. data/config/routes.rb +3 -0
  14. data/lib/tessa/active_storage/asset_wrapper.rb +24 -0
  15. data/lib/tessa/engine.rb +5 -0
  16. data/lib/tessa/model/dynamic_extensions.rb +151 -0
  17. data/lib/tessa/model.rb +27 -36
  18. data/lib/tessa/rack_upload_proxy.rb +18 -10
  19. data/lib/tessa/version.rb +1 -1
  20. data/lib/tessa/view_helpers.rb +4 -2
  21. data/lib/tessa.rb +30 -0
  22. data/package.json +43 -0
  23. data/rollup.config.js +44 -0
  24. data/spec/dummy/.gitignore +27 -0
  25. data/spec/dummy/README.md +24 -0
  26. data/spec/dummy/Rakefile +6 -0
  27. data/spec/dummy/app/assets/config/manifest.js +2 -0
  28. data/spec/dummy/app/assets/images/.keep +0 -0
  29. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  31. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy/app/jobs/application_job.rb +2 -0
  34. data/spec/dummy/app/models/concerns/.keep +0 -0
  35. data/spec/dummy/app/models/multiple_asset_model.rb +8 -0
  36. data/spec/dummy/app/models/single_asset_model.rb +5 -0
  37. data/spec/dummy/app/models/single_asset_model_form.rb +25 -0
  38. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  39. data/spec/dummy/bin/bundle +3 -0
  40. data/spec/dummy/bin/rails +4 -0
  41. data/spec/dummy/bin/rake +4 -0
  42. data/spec/dummy/bin/setup +28 -0
  43. data/spec/dummy/bin/update +28 -0
  44. data/spec/dummy/bin/yarn +11 -0
  45. data/spec/dummy/config/application.rb +33 -0
  46. data/spec/dummy/config/boot.rb +3 -0
  47. data/spec/dummy/config/credentials.yml.enc +1 -0
  48. data/spec/dummy/config/database.yml +25 -0
  49. data/spec/dummy/config/environment.rb +5 -0
  50. data/spec/dummy/config/environments/development.rb +47 -0
  51. data/spec/dummy/config/environments/production.rb +76 -0
  52. data/spec/dummy/config/environments/test.rb +43 -0
  53. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  54. data/spec/dummy/config/initializers/assets.rb +14 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  57. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  58. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  59. data/spec/dummy/config/initializers/inflections.rb +16 -0
  60. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  61. data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
  62. data/spec/dummy/config/locales/en.yml +33 -0
  63. data/spec/dummy/config/puma.rb +37 -0
  64. data/spec/dummy/config/routes.rb +3 -0
  65. data/spec/dummy/config/storage.yml +3 -0
  66. data/spec/dummy/config.ru +5 -0
  67. data/spec/dummy/db/migrate/20220606221557_create_active_storage_tables.active_storage.rb +27 -0
  68. data/spec/dummy/db/migrate/20220606221900_create_single_asset_models.rb +10 -0
  69. data/spec/dummy/db/migrate/20220607191519_create_multiple_asset_models.rb +10 -0
  70. data/spec/dummy/db/schema.rb +50 -0
  71. data/spec/dummy/lib/assets/.keep +0 -0
  72. data/spec/dummy/lib/tasks/.keep +0 -0
  73. data/spec/dummy/log/.keep +0 -0
  74. data/spec/dummy/package.json +5 -0
  75. data/spec/dummy/public/404.html +67 -0
  76. data/spec/dummy/public/422.html +67 -0
  77. data/spec/dummy/public/500.html +66 -0
  78. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  79. data/spec/dummy/public/apple-touch-icon.png +0 -0
  80. data/spec/dummy/public/favicon.ico +0 -0
  81. data/spec/dummy/public/robots.txt +1 -0
  82. data/spec/dummy/tmp/.keep +0 -0
  83. data/spec/dummy/vendor/.keep +0 -0
  84. data/spec/rails_helper.rb +14 -0
  85. data/spec/tessa/model_spec.rb +195 -262
  86. data/spec/tessa/rack_upload_proxy_spec.rb +23 -81
  87. data/tessa.gemspec +7 -2
  88. data/yarn.lock +1661 -0
  89. metadata +179 -16
  90. data/circle.yml +0 -3
@@ -0,0 +1,662 @@
1
+ (function(factory) {
2
+ typeof define === "function" && define.amd ? define(factory) : factory();
3
+ })((function() {
4
+ "use strict";
5
+ var sparkMd5 = {
6
+ exports: {}
7
+ };
8
+ (function(module, exports) {
9
+ (function(factory) {
10
+ {
11
+ module.exports = factory();
12
+ }
13
+ })((function(undefined$1) {
14
+ var hex_chr = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ];
15
+ function md5cycle(x, k) {
16
+ var a = x[0], b = x[1], c = x[2], d = x[3];
17
+ a += (b & c | ~b & d) + k[0] - 680876936 | 0;
18
+ a = (a << 7 | a >>> 25) + b | 0;
19
+ d += (a & b | ~a & c) + k[1] - 389564586 | 0;
20
+ d = (d << 12 | d >>> 20) + a | 0;
21
+ c += (d & a | ~d & b) + k[2] + 606105819 | 0;
22
+ c = (c << 17 | c >>> 15) + d | 0;
23
+ b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
24
+ b = (b << 22 | b >>> 10) + c | 0;
25
+ a += (b & c | ~b & d) + k[4] - 176418897 | 0;
26
+ a = (a << 7 | a >>> 25) + b | 0;
27
+ d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
28
+ d = (d << 12 | d >>> 20) + a | 0;
29
+ c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
30
+ c = (c << 17 | c >>> 15) + d | 0;
31
+ b += (c & d | ~c & a) + k[7] - 45705983 | 0;
32
+ b = (b << 22 | b >>> 10) + c | 0;
33
+ a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
34
+ a = (a << 7 | a >>> 25) + b | 0;
35
+ d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
36
+ d = (d << 12 | d >>> 20) + a | 0;
37
+ c += (d & a | ~d & b) + k[10] - 42063 | 0;
38
+ c = (c << 17 | c >>> 15) + d | 0;
39
+ b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
40
+ b = (b << 22 | b >>> 10) + c | 0;
41
+ a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
42
+ a = (a << 7 | a >>> 25) + b | 0;
43
+ d += (a & b | ~a & c) + k[13] - 40341101 | 0;
44
+ d = (d << 12 | d >>> 20) + a | 0;
45
+ c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
46
+ c = (c << 17 | c >>> 15) + d | 0;
47
+ b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
48
+ b = (b << 22 | b >>> 10) + c | 0;
49
+ a += (b & d | c & ~d) + k[1] - 165796510 | 0;
50
+ a = (a << 5 | a >>> 27) + b | 0;
51
+ d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
52
+ d = (d << 9 | d >>> 23) + a | 0;
53
+ c += (d & b | a & ~b) + k[11] + 643717713 | 0;
54
+ c = (c << 14 | c >>> 18) + d | 0;
55
+ b += (c & a | d & ~a) + k[0] - 373897302 | 0;
56
+ b = (b << 20 | b >>> 12) + c | 0;
57
+ a += (b & d | c & ~d) + k[5] - 701558691 | 0;
58
+ a = (a << 5 | a >>> 27) + b | 0;
59
+ d += (a & c | b & ~c) + k[10] + 38016083 | 0;
60
+ d = (d << 9 | d >>> 23) + a | 0;
61
+ c += (d & b | a & ~b) + k[15] - 660478335 | 0;
62
+ c = (c << 14 | c >>> 18) + d | 0;
63
+ b += (c & a | d & ~a) + k[4] - 405537848 | 0;
64
+ b = (b << 20 | b >>> 12) + c | 0;
65
+ a += (b & d | c & ~d) + k[9] + 568446438 | 0;
66
+ a = (a << 5 | a >>> 27) + b | 0;
67
+ d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
68
+ d = (d << 9 | d >>> 23) + a | 0;
69
+ c += (d & b | a & ~b) + k[3] - 187363961 | 0;
70
+ c = (c << 14 | c >>> 18) + d | 0;
71
+ b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
72
+ b = (b << 20 | b >>> 12) + c | 0;
73
+ a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
74
+ a = (a << 5 | a >>> 27) + b | 0;
75
+ d += (a & c | b & ~c) + k[2] - 51403784 | 0;
76
+ d = (d << 9 | d >>> 23) + a | 0;
77
+ c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
78
+ c = (c << 14 | c >>> 18) + d | 0;
79
+ b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
80
+ b = (b << 20 | b >>> 12) + c | 0;
81
+ a += (b ^ c ^ d) + k[5] - 378558 | 0;
82
+ a = (a << 4 | a >>> 28) + b | 0;
83
+ d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
84
+ d = (d << 11 | d >>> 21) + a | 0;
85
+ c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
86
+ c = (c << 16 | c >>> 16) + d | 0;
87
+ b += (c ^ d ^ a) + k[14] - 35309556 | 0;
88
+ b = (b << 23 | b >>> 9) + c | 0;
89
+ a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
90
+ a = (a << 4 | a >>> 28) + b | 0;
91
+ d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
92
+ d = (d << 11 | d >>> 21) + a | 0;
93
+ c += (d ^ a ^ b) + k[7] - 155497632 | 0;
94
+ c = (c << 16 | c >>> 16) + d | 0;
95
+ b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
96
+ b = (b << 23 | b >>> 9) + c | 0;
97
+ a += (b ^ c ^ d) + k[13] + 681279174 | 0;
98
+ a = (a << 4 | a >>> 28) + b | 0;
99
+ d += (a ^ b ^ c) + k[0] - 358537222 | 0;
100
+ d = (d << 11 | d >>> 21) + a | 0;
101
+ c += (d ^ a ^ b) + k[3] - 722521979 | 0;
102
+ c = (c << 16 | c >>> 16) + d | 0;
103
+ b += (c ^ d ^ a) + k[6] + 76029189 | 0;
104
+ b = (b << 23 | b >>> 9) + c | 0;
105
+ a += (b ^ c ^ d) + k[9] - 640364487 | 0;
106
+ a = (a << 4 | a >>> 28) + b | 0;
107
+ d += (a ^ b ^ c) + k[12] - 421815835 | 0;
108
+ d = (d << 11 | d >>> 21) + a | 0;
109
+ c += (d ^ a ^ b) + k[15] + 530742520 | 0;
110
+ c = (c << 16 | c >>> 16) + d | 0;
111
+ b += (c ^ d ^ a) + k[2] - 995338651 | 0;
112
+ b = (b << 23 | b >>> 9) + c | 0;
113
+ a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
114
+ a = (a << 6 | a >>> 26) + b | 0;
115
+ d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
116
+ d = (d << 10 | d >>> 22) + a | 0;
117
+ c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
118
+ c = (c << 15 | c >>> 17) + d | 0;
119
+ b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
120
+ b = (b << 21 | b >>> 11) + c | 0;
121
+ a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
122
+ a = (a << 6 | a >>> 26) + b | 0;
123
+ d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
124
+ d = (d << 10 | d >>> 22) + a | 0;
125
+ c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
126
+ c = (c << 15 | c >>> 17) + d | 0;
127
+ b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
128
+ b = (b << 21 | b >>> 11) + c | 0;
129
+ a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
130
+ a = (a << 6 | a >>> 26) + b | 0;
131
+ d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
132
+ d = (d << 10 | d >>> 22) + a | 0;
133
+ c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
134
+ c = (c << 15 | c >>> 17) + d | 0;
135
+ b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
136
+ b = (b << 21 | b >>> 11) + c | 0;
137
+ a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
138
+ a = (a << 6 | a >>> 26) + b | 0;
139
+ d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
140
+ d = (d << 10 | d >>> 22) + a | 0;
141
+ c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
142
+ c = (c << 15 | c >>> 17) + d | 0;
143
+ b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
144
+ b = (b << 21 | b >>> 11) + c | 0;
145
+ x[0] = a + x[0] | 0;
146
+ x[1] = b + x[1] | 0;
147
+ x[2] = c + x[2] | 0;
148
+ x[3] = d + x[3] | 0;
149
+ }
150
+ function md5blk(s) {
151
+ var md5blks = [], i;
152
+ for (i = 0; i < 64; i += 4) {
153
+ md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
154
+ }
155
+ return md5blks;
156
+ }
157
+ function md5blk_array(a) {
158
+ var md5blks = [], i;
159
+ for (i = 0; i < 64; i += 4) {
160
+ md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
161
+ }
162
+ return md5blks;
163
+ }
164
+ function md51(s) {
165
+ var n = s.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;
166
+ for (i = 64; i <= n; i += 64) {
167
+ md5cycle(state, md5blk(s.substring(i - 64, i)));
168
+ }
169
+ s = s.substring(i - 64);
170
+ length = s.length;
171
+ tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
172
+ for (i = 0; i < length; i += 1) {
173
+ tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);
174
+ }
175
+ tail[i >> 2] |= 128 << (i % 4 << 3);
176
+ if (i > 55) {
177
+ md5cycle(state, tail);
178
+ for (i = 0; i < 16; i += 1) {
179
+ tail[i] = 0;
180
+ }
181
+ }
182
+ tmp = n * 8;
183
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
184
+ lo = parseInt(tmp[2], 16);
185
+ hi = parseInt(tmp[1], 16) || 0;
186
+ tail[14] = lo;
187
+ tail[15] = hi;
188
+ md5cycle(state, tail);
189
+ return state;
190
+ }
191
+ function md51_array(a) {
192
+ var n = a.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;
193
+ for (i = 64; i <= n; i += 64) {
194
+ md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
195
+ }
196
+ a = i - 64 < n ? a.subarray(i - 64) : new Uint8Array(0);
197
+ length = a.length;
198
+ tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
199
+ for (i = 0; i < length; i += 1) {
200
+ tail[i >> 2] |= a[i] << (i % 4 << 3);
201
+ }
202
+ tail[i >> 2] |= 128 << (i % 4 << 3);
203
+ if (i > 55) {
204
+ md5cycle(state, tail);
205
+ for (i = 0; i < 16; i += 1) {
206
+ tail[i] = 0;
207
+ }
208
+ }
209
+ tmp = n * 8;
210
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
211
+ lo = parseInt(tmp[2], 16);
212
+ hi = parseInt(tmp[1], 16) || 0;
213
+ tail[14] = lo;
214
+ tail[15] = hi;
215
+ md5cycle(state, tail);
216
+ return state;
217
+ }
218
+ function rhex(n) {
219
+ var s = "", j;
220
+ for (j = 0; j < 4; j += 1) {
221
+ s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];
222
+ }
223
+ return s;
224
+ }
225
+ function hex(x) {
226
+ var i;
227
+ for (i = 0; i < x.length; i += 1) {
228
+ x[i] = rhex(x[i]);
229
+ }
230
+ return x.join("");
231
+ }
232
+ if (hex(md51("hello")) !== "5d41402abc4b2a76b9719d911017c592") ;
233
+ if (typeof ArrayBuffer !== "undefined" && !ArrayBuffer.prototype.slice) {
234
+ (function() {
235
+ function clamp(val, length) {
236
+ val = val | 0 || 0;
237
+ if (val < 0) {
238
+ return Math.max(val + length, 0);
239
+ }
240
+ return Math.min(val, length);
241
+ }
242
+ ArrayBuffer.prototype.slice = function(from, to) {
243
+ var length = this.byteLength, begin = clamp(from, length), end = length, num, target, targetArray, sourceArray;
244
+ if (to !== undefined$1) {
245
+ end = clamp(to, length);
246
+ }
247
+ if (begin > end) {
248
+ return new ArrayBuffer(0);
249
+ }
250
+ num = end - begin;
251
+ target = new ArrayBuffer(num);
252
+ targetArray = new Uint8Array(target);
253
+ sourceArray = new Uint8Array(this, begin, num);
254
+ targetArray.set(sourceArray);
255
+ return target;
256
+ };
257
+ })();
258
+ }
259
+ function toUtf8(str) {
260
+ if (/[\u0080-\uFFFF]/.test(str)) {
261
+ str = unescape(encodeURIComponent(str));
262
+ }
263
+ return str;
264
+ }
265
+ function utf8Str2ArrayBuffer(str, returnUInt8Array) {
266
+ var length = str.length, buff = new ArrayBuffer(length), arr = new Uint8Array(buff), i;
267
+ for (i = 0; i < length; i += 1) {
268
+ arr[i] = str.charCodeAt(i);
269
+ }
270
+ return returnUInt8Array ? arr : buff;
271
+ }
272
+ function arrayBuffer2Utf8Str(buff) {
273
+ return String.fromCharCode.apply(null, new Uint8Array(buff));
274
+ }
275
+ function concatenateArrayBuffers(first, second, returnUInt8Array) {
276
+ var result = new Uint8Array(first.byteLength + second.byteLength);
277
+ result.set(new Uint8Array(first));
278
+ result.set(new Uint8Array(second), first.byteLength);
279
+ return returnUInt8Array ? result : result.buffer;
280
+ }
281
+ function hexToBinaryString(hex) {
282
+ var bytes = [], length = hex.length, x;
283
+ for (x = 0; x < length - 1; x += 2) {
284
+ bytes.push(parseInt(hex.substr(x, 2), 16));
285
+ }
286
+ return String.fromCharCode.apply(String, bytes);
287
+ }
288
+ function SparkMD5() {
289
+ this.reset();
290
+ }
291
+ SparkMD5.prototype.append = function(str) {
292
+ this.appendBinary(toUtf8(str));
293
+ return this;
294
+ };
295
+ SparkMD5.prototype.appendBinary = function(contents) {
296
+ this._buff += contents;
297
+ this._length += contents.length;
298
+ var length = this._buff.length, i;
299
+ for (i = 64; i <= length; i += 64) {
300
+ md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
301
+ }
302
+ this._buff = this._buff.substring(i - 64);
303
+ return this;
304
+ };
305
+ SparkMD5.prototype.end = function(raw) {
306
+ 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;
307
+ for (i = 0; i < length; i += 1) {
308
+ tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);
309
+ }
310
+ this._finish(tail, length);
311
+ ret = hex(this._hash);
312
+ if (raw) {
313
+ ret = hexToBinaryString(ret);
314
+ }
315
+ this.reset();
316
+ return ret;
317
+ };
318
+ SparkMD5.prototype.reset = function() {
319
+ this._buff = "";
320
+ this._length = 0;
321
+ this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];
322
+ return this;
323
+ };
324
+ SparkMD5.prototype.getState = function() {
325
+ return {
326
+ buff: this._buff,
327
+ length: this._length,
328
+ hash: this._hash.slice()
329
+ };
330
+ };
331
+ SparkMD5.prototype.setState = function(state) {
332
+ this._buff = state.buff;
333
+ this._length = state.length;
334
+ this._hash = state.hash;
335
+ return this;
336
+ };
337
+ SparkMD5.prototype.destroy = function() {
338
+ delete this._hash;
339
+ delete this._buff;
340
+ delete this._length;
341
+ };
342
+ SparkMD5.prototype._finish = function(tail, length) {
343
+ var i = length, tmp, lo, hi;
344
+ tail[i >> 2] |= 128 << (i % 4 << 3);
345
+ if (i > 55) {
346
+ md5cycle(this._hash, tail);
347
+ for (i = 0; i < 16; i += 1) {
348
+ tail[i] = 0;
349
+ }
350
+ }
351
+ tmp = this._length * 8;
352
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
353
+ lo = parseInt(tmp[2], 16);
354
+ hi = parseInt(tmp[1], 16) || 0;
355
+ tail[14] = lo;
356
+ tail[15] = hi;
357
+ md5cycle(this._hash, tail);
358
+ };
359
+ SparkMD5.hash = function(str, raw) {
360
+ return SparkMD5.hashBinary(toUtf8(str), raw);
361
+ };
362
+ SparkMD5.hashBinary = function(content, raw) {
363
+ var hash = md51(content), ret = hex(hash);
364
+ return raw ? hexToBinaryString(ret) : ret;
365
+ };
366
+ SparkMD5.ArrayBuffer = function() {
367
+ this.reset();
368
+ };
369
+ SparkMD5.ArrayBuffer.prototype.append = function(arr) {
370
+ var buff = concatenateArrayBuffers(this._buff.buffer, arr, true), length = buff.length, i;
371
+ this._length += arr.byteLength;
372
+ for (i = 64; i <= length; i += 64) {
373
+ md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
374
+ }
375
+ this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);
376
+ return this;
377
+ };
378
+ SparkMD5.ArrayBuffer.prototype.end = function(raw) {
379
+ 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;
380
+ for (i = 0; i < length; i += 1) {
381
+ tail[i >> 2] |= buff[i] << (i % 4 << 3);
382
+ }
383
+ this._finish(tail, length);
384
+ ret = hex(this._hash);
385
+ if (raw) {
386
+ ret = hexToBinaryString(ret);
387
+ }
388
+ this.reset();
389
+ return ret;
390
+ };
391
+ SparkMD5.ArrayBuffer.prototype.reset = function() {
392
+ this._buff = new Uint8Array(0);
393
+ this._length = 0;
394
+ this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];
395
+ return this;
396
+ };
397
+ SparkMD5.ArrayBuffer.prototype.getState = function() {
398
+ var state = SparkMD5.prototype.getState.call(this);
399
+ state.buff = arrayBuffer2Utf8Str(state.buff);
400
+ return state;
401
+ };
402
+ SparkMD5.ArrayBuffer.prototype.setState = function(state) {
403
+ state.buff = utf8Str2ArrayBuffer(state.buff, true);
404
+ return SparkMD5.prototype.setState.call(this, state);
405
+ };
406
+ SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
407
+ SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
408
+ SparkMD5.ArrayBuffer.hash = function(arr, raw) {
409
+ var hash = md51_array(new Uint8Array(arr)), ret = hex(hash);
410
+ return raw ? hexToBinaryString(ret) : ret;
411
+ };
412
+ return SparkMD5;
413
+ }));
414
+ })(sparkMd5);
415
+ var SparkMD5 = sparkMd5.exports;
416
+ const fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
417
+ class FileChecksum {
418
+ static create(file, callback) {
419
+ const instance = new FileChecksum(file);
420
+ instance.create(callback);
421
+ }
422
+ constructor(file) {
423
+ this.file = file;
424
+ this.chunkSize = 2097152;
425
+ this.chunkCount = Math.ceil(this.file.size / this.chunkSize);
426
+ this.chunkIndex = 0;
427
+ }
428
+ create(callback) {
429
+ this.callback = callback;
430
+ this.md5Buffer = new SparkMD5.ArrayBuffer;
431
+ this.fileReader = new FileReader;
432
+ this.fileReader.addEventListener("load", (event => this.fileReaderDidLoad(event)));
433
+ this.fileReader.addEventListener("error", (event => this.fileReaderDidError(event)));
434
+ this.readNextChunk();
435
+ }
436
+ fileReaderDidLoad(event) {
437
+ this.md5Buffer.append(event.target.result);
438
+ if (!this.readNextChunk()) {
439
+ const binaryDigest = this.md5Buffer.end(true);
440
+ const base64digest = btoa(binaryDigest);
441
+ this.callback(null, base64digest);
442
+ }
443
+ }
444
+ fileReaderDidError(event) {
445
+ this.callback(`Error reading ${this.file.name}`);
446
+ }
447
+ readNextChunk() {
448
+ if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {
449
+ const start = this.chunkIndex * this.chunkSize;
450
+ const end = Math.min(start + this.chunkSize, this.file.size);
451
+ const bytes = fileSlice.call(this.file, start, end);
452
+ this.fileReader.readAsArrayBuffer(bytes);
453
+ this.chunkIndex++;
454
+ return true;
455
+ } else {
456
+ return false;
457
+ }
458
+ }
459
+ }
460
+ var $;
461
+ window.WCC || (window.WCC = {});
462
+ $ = window.jQuery;
463
+ Dropzone.autoDiscover = false;
464
+ window.WCC.Dropzone = class Dropzone extends window.Dropzone {
465
+ uploadFile(file) {
466
+ var handleError, headerName, headerValue, headers, progressObj, ref, ref1, response, updateProgress, xhr;
467
+ xhr = new XMLHttpRequest;
468
+ file.xhr = xhr;
469
+ xhr.open(file.uploadMethod, file.uploadURL, true);
470
+ ref = file.uploadHeaders;
471
+ for (headerName in ref) {
472
+ headerValue = ref[headerName];
473
+ xhr.setRequestHeader(headerName, headerValue);
474
+ }
475
+ response = null;
476
+ handleError = () => this._errorProcessing([ file ], response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
477
+ updateProgress = e => {
478
+ var allFilesFinished, progress;
479
+ if (e != null) {
480
+ progress = 100 * e.loaded / e.total;
481
+ file.upload = {
482
+ progress: progress,
483
+ total: e.total,
484
+ bytesSent: e.loaded
485
+ };
486
+ } else {
487
+ allFilesFinished = true;
488
+ progress = 100;
489
+ if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
490
+ allFilesFinished = false;
491
+ }
492
+ file.upload.progress = progress;
493
+ file.upload.bytesSent = file.upload.total;
494
+ if (allFilesFinished) {
495
+ return;
496
+ }
497
+ }
498
+ return this.emit("uploadprogress", file, progress, file.upload.bytesSent);
499
+ };
500
+ xhr.onload = e => {
501
+ var ref1;
502
+ if (file.status === WCC.Dropzone.CANCELED) {
503
+ return;
504
+ }
505
+ if (xhr.readyState !== 4) {
506
+ return;
507
+ }
508
+ response = xhr.responseText;
509
+ if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
510
+ try {
511
+ response = JSON.parse(response);
512
+ } catch (error1) {
513
+ e = error1;
514
+ response = "Invalid JSON response from server.";
515
+ }
516
+ }
517
+ updateProgress();
518
+ if (!(200 <= (ref1 = xhr.status) && ref1 < 300)) {
519
+ return handleError();
520
+ } else {
521
+ return this._finished([ file ], response, e);
522
+ }
523
+ };
524
+ xhr.onerror = () => {
525
+ if (file.status === WCC.Dropzone.CANCELED) {
526
+ return;
527
+ }
528
+ return handleError();
529
+ };
530
+ progressObj = (ref1 = xhr.upload) != null ? ref1 : xhr;
531
+ progressObj.onprogress = updateProgress;
532
+ headers = {
533
+ Accept: "application/json",
534
+ "Cache-Control": "no-cache",
535
+ "X-Requested-With": "XMLHttpRequest"
536
+ };
537
+ if (this.options.headers) {
538
+ extend(headers, this.options.headers);
539
+ }
540
+ for (headerName in headers) {
541
+ headerValue = headers[headerName];
542
+ xhr.setRequestHeader(headerName, headerValue);
543
+ }
544
+ this.emit("sending", file, xhr);
545
+ return xhr.send(file);
546
+ }
547
+ uploadFiles(files) {
548
+ var file, l, len, results;
549
+ results = [];
550
+ for (l = 0, len = files.length; l < len; l++) {
551
+ file = files[l];
552
+ results.push(this.uploadFile(file));
553
+ }
554
+ return results;
555
+ }
556
+ };
557
+ WCC.Dropzone.uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?";
558
+ WCC.Dropzone.prototype.defaultOptions.url = "UNUSED";
559
+ WCC.Dropzone.prototype.defaultOptions.dictDefaultMessage = "Drop files or click to upload.";
560
+ WCC.Dropzone.prototype.defaultOptions.accept = function(file, done) {
561
+ var dz, postData, tessaParams;
562
+ dz = $(file._removeLink).closest(".tessa-upload").first();
563
+ tessaParams = dz.data("tessa-params") || {};
564
+ postData = {
565
+ name: file.name,
566
+ size: file.size,
567
+ mime_type: file.type
568
+ };
569
+ postData = $.extend(postData, tessaParams);
570
+ return FileChecksum.create(file, (function(error, checksum) {
571
+ if (error) {
572
+ return done(error);
573
+ }
574
+ postData["checksum"] = checksum;
575
+ return $.ajax("/tessa/uploads", {
576
+ type: "POST",
577
+ data: postData,
578
+ success: function(response) {
579
+ file.uploadURL = response.upload_url;
580
+ file.uploadMethod = response.upload_method;
581
+ file.uploadHeaders = response.upload_headers;
582
+ file.assetID = response.asset_id;
583
+ return done();
584
+ },
585
+ error: function(response) {
586
+ return done("Failed to initiate the upload process!");
587
+ }
588
+ });
589
+ }));
590
+ };
591
+ window.WCC.tessaInit = function(sel) {
592
+ sel = sel || "form:has(.tessa-upload)";
593
+ $(sel).each((function(i, form) {
594
+ var $form;
595
+ $form = $(form);
596
+ return $form.bind("submit", (function(event) {
597
+ var safeToSubmit;
598
+ safeToSubmit = true;
599
+ $form.find(".tessa-upload").each((function(j, dropzoneElement) {
600
+ return $(dropzoneElement.dropzone.files).each((function(k, file) {
601
+ if (file.status != null && file.status !== WCC.Dropzone.SUCCESS) {
602
+ return safeToSubmit = false;
603
+ }
604
+ }));
605
+ }));
606
+ if (!safeToSubmit && !confirm(WCC.Dropzone.uploadPendingWarning)) {
607
+ return false;
608
+ }
609
+ }));
610
+ }));
611
+ return $(".tessa-upload", sel).each((function(i, item) {
612
+ var $item, args, dropzone, inputPrefix, updateAction;
613
+ $item = $(item);
614
+ args = {
615
+ maxFiles: 1,
616
+ addRemoveLinks: true
617
+ };
618
+ $.extend(args, $item.data("dropzone-options"));
619
+ if ($item.hasClass("multiple")) {
620
+ args.maxFiles = null;
621
+ }
622
+ inputPrefix = $item.data("asset-field-prefix");
623
+ dropzone = new WCC.Dropzone(item, args);
624
+ $item.find('input[type="hidden"]').each((function(j, input) {
625
+ var $input, mockFile;
626
+ $input = $(input);
627
+ mockFile = $input.data("meta");
628
+ mockFile.accepted = true;
629
+ dropzone.options.addedfile.call(dropzone, mockFile);
630
+ dropzone.options.thumbnail.call(dropzone, mockFile, mockFile.url);
631
+ dropzone.emit("complete", mockFile);
632
+ return dropzone.files.push(mockFile);
633
+ }));
634
+ updateAction = function(file) {
635
+ var actionInput, inputID;
636
+ if (file.assetID == null) {
637
+ return;
638
+ }
639
+ inputID = `#tessa_asset_action_${file.assetID}`;
640
+ actionInput = $(inputID);
641
+ if (!actionInput.length) {
642
+ actionInput = $('<input type="hidden">').attr({
643
+ id: inputID,
644
+ name: `${inputPrefix}[${file.assetID}][action]`
645
+ }).appendTo(item);
646
+ }
647
+ return actionInput.val(file.action);
648
+ };
649
+ dropzone.on("success", (function(file) {
650
+ file.action = "add";
651
+ return updateAction(file);
652
+ }));
653
+ return dropzone.on("removedfile", (function(file) {
654
+ file.action = "remove";
655
+ return updateAction(file);
656
+ }));
657
+ }));
658
+ };
659
+ $((function() {
660
+ return window.WCC.tessaInit();
661
+ }));
662
+ }));